1208538Sraj/**************************************************************** 2208538Sraj 3208538SrajThe author of this software is David M. Gay. 4208538Sraj 5208538SrajCopyright (C) 1998 by Lucent Technologies 6208538SrajAll Rights Reserved 7208538Sraj 8208538SrajPermission to use, copy, modify, and distribute this software and 9208538Srajits documentation for any purpose and without fee is hereby 10208538Srajgranted, provided that the above copyright notice appear in all 11208538Srajcopies and that both that the copyright notice and this 12208538Srajpermission notice and warranty disclaimer appear in supporting 13208538Srajdocumentation, and that the name of Lucent or any of its entities 14208538Srajnot be used in advertising or publicity pertaining to 15208538Srajdistribution of the software without specific, written prior 16208538Srajpermission. 17208538Sraj 18208538SrajLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 19208538SrajINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 20208538SrajIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 21208538SrajSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22208538SrajWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 23208538SrajIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 24208538SrajARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 25208538SrajTHIS SOFTWARE. 26208538Sraj 27208538Sraj****************************************************************/ 28208538Sraj 29208538Sraj/* Please send bug reports to David M. Gay (dmg at acm dot org, 30208538Sraj * with " at " changed at "@" and " dot " changed to "."). */ 31208538Sraj 32208538Sraj#include "gdtoaimp.h" 33208538Sraj 34208538Sraj#undef _0 35208538Sraj#undef _1 36233230Sraj 37233230Sraj/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */ 38233230Sraj 39208538Sraj#ifdef IEEE_MC68k 40208538Sraj#define _0 0 41275763Sandrew#define _1 1 42208538Sraj#define _2 2 43208538Sraj#endif 44208538Sraj#ifdef IEEE_8087 45208538Sraj#define _0 2 46208538Sraj#define _1 1 47208538Sraj#define _2 0 48208538Sraj#endif 49208538Sraj 50208538Sraj char* 51208538Sraj#ifdef KR_headers 52208538Srajg_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize; 53208538Sraj#else 54208538Srajg_xLfmt(char *buf, void *V, int ndig, size_t bufsize) 55235529Skientzle#endif 56235529Skientzle{ 57233230Sraj static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 }; 58233230Sraj char *b, *s, *se; 59233230Sraj ULong bits[2], *L, sign; 60243693Sgonzo int decpt, ex, i, mode; 61243693Sgonzo#ifdef Honor_FLT_ROUNDS 62247201Skientzle#include "gdtoa_fltrnds.h" 63247250Skientzle#else 64247201Skientzle#define fpi &fpi0 65247250Skientzle#endif 66247250Skientzle 67208538Sraj if (ndig < 0) 68235529Skientzle ndig = 0; 69235529Skientzle if (bufsize < ndig + 10) 70247250Skientzle return 0; 71247250Skientzle 72247250Skientzle L = (ULong*)V; 73235529Skientzle sign = L[_0] & 0x80000000L; 74208538Sraj bits[1] = L[_1]; 75243693Sgonzo bits[0] = L[_2]; 76243693Sgonzo if ( (ex = (L[_0] >> 16) & 0x7fff) !=0) { 77208538Sraj if (ex == 0x7fff) { 78208538Sraj /* Infinity or NaN */ 79243693Sgonzo if (bits[0] | bits[1]) 80208538Sraj b = strcp(buf, "NaN"); 81208538Sraj else { 82208538Sraj b = buf; 83208538Sraj if (sign) 84208538Sraj *b++ = '-'; 85208538Sraj b = strcp(b, "Infinity"); 86208538Sraj } 87208538Sraj return b; 88243693Sgonzo } 89208538Sraj i = STRTOG_Normal; 90208538Sraj } 91208538Sraj else if (bits[0] | bits[1]) { 92208538Sraj i = STRTOG_Denormal; 93275762Sandrew } 94275762Sandrew else { 95275762Sandrew b = buf; 96208538Sraj#ifndef IGNORE_ZERO_SIGN 97208538Sraj if (sign) 98208538Sraj *b++ = '-'; 99243693Sgonzo#endif 100243693Sgonzo *b++ = '0'; 101243693Sgonzo *b = 0; 102243693Sgonzo return b; 103243693Sgonzo } 104243693Sgonzo ex -= 0x3fff + 63; 105243693Sgonzo mode = 2; 106243693Sgonzo if (ndig <= 0) { 107243693Sgonzo if (bufsize < 32) 108243693Sgonzo return 0; 109243693Sgonzo mode = 0; 110208538Sraj } 111208538Sraj s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se); 112208538Sraj return g__fmt(buf, s, se, decpt, sign, bufsize); 113208538Sraj } 114208538Sraj