/****************************************************************12The author of this software is David M. Gay.34Copyright (C) 1998 by Lucent Technologies5All Rights Reserved67Permission to use, copy, modify, and distribute this software and8its documentation for any purpose and without fee is hereby9granted, provided that the above copyright notice appear in all10copies and that both that the copyright notice and this11permission notice and warranty disclaimer appear in supporting12documentation, and that the name of Lucent or any of its entities13not be used in advertising or publicity pertaining to14distribution of the software without specific, written prior15permission.1617LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,18INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.19IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY20SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES21WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER22IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,23ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF24THIS SOFTWARE.2526****************************************************************/2728/* Please send bug reports to David M. Gay (dmg at acm dot org,29* with " at " changed at "@" and " dot " changed to "."). */3031#include "gdtoaimp.h"3233#undef _034#undef _13536/* one or the other of IEEE_MC68k or IEEE_8087 should be #defined */3738#ifdef IEEE_MC68k39#define _0 040#define _1 141#define _2 242#define _3 343#define _4 444#endif45#ifdef IEEE_808746#define _0 447#define _1 348#define _2 249#define _3 150#define _4 051#endif5253char*54#ifdef KR_headers55g_xfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;56#else57g_xfmt(char *buf, void *V, int ndig, size_t bufsize)58#endif59{60static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };61char *b, *s, *se;62ULong bits[2], sign;63UShort *L;64int decpt, ex, i, mode;65#ifdef Honor_FLT_ROUNDS66#include "gdtoa_fltrnds.h"67#else68#define fpi &fpi069#endif7071if (ndig < 0)72ndig = 0;73if (bufsize < ndig + 10)74return 0;7576L = (UShort *)V;77sign = L[_0] & 0x8000;78bits[1] = (L[_1] << 16) | L[_2];79bits[0] = (L[_3] << 16) | L[_4];80if ( (ex = L[_0] & 0x7fff) !=0) {81if (ex == 0x7fff) {82/* Infinity or NaN */83if (bits[0] | bits[1])84b = strcp(buf, "NaN");85else {86b = buf;87if (sign)88*b++ = '-';89b = strcp(b, "Infinity");90}91return b;92}93i = STRTOG_Normal;94}95else if (bits[0] | bits[1]) {96i = STRTOG_Denormal;97ex = 1;98}99else {100b = buf;101#ifndef IGNORE_ZERO_SIGN102if (sign)103*b++ = '-';104#endif105*b++ = '0';106*b = 0;107return b;108}109ex -= 0x3fff + 63;110mode = 2;111if (ndig <= 0) {112if (bufsize < 32)113return 0;114mode = 0;115}116s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);117return g__fmt(buf, s, se, decpt, sign, bufsize);118}119120121