/****************************************************************12The author of this software is David M. Gay.34Copyright (C) 1998, 2000 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#endif44#ifdef IEEE_808745#define _0 346#define _1 247#define _2 148#define _3 049#endif5051char*52#ifdef KR_headers53g_Qfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;54#else55g_Qfmt(char *buf, void *V, int ndig, size_t bufsize)56#endif57{58static FPI fpi0 = { 113, 1-16383-113+1, 32766 - 16383 - 113 + 1, 1, 0 };59char *b, *s, *se;60ULong bits[4], *L, sign;61int decpt, ex, i, mode;62#ifdef Honor_FLT_ROUNDS63#include "gdtoa_fltrnds.h"64#else65#define fpi &fpi066#endif6768if (ndig < 0)69ndig = 0;70if (bufsize < ndig + 10)71return 0;7273L = (ULong*)V;74sign = L[_0] & 0x80000000L;75bits[3] = L[_0] & 0xffff;76bits[2] = L[_1];77bits[1] = L[_2];78bits[0] = L[_3];79b = buf;80if ( (ex = (L[_0] & 0x7fff0000L) >> 16) !=0) {81if (ex == 0x7fff) {82/* Infinity or NaN */83if (bits[0] | bits[1] | bits[2] | bits[3])84b = strcp(b, "NaN");85else {86b = buf;87if (sign)88*b++ = '-';89b = strcp(b, "Infinity");90}91return b;92}93i = STRTOG_Normal;94bits[3] |= 0x10000;95}96else if (bits[0] | bits[1] | bits[2] | bits[3]) {97i = STRTOG_Denormal;98ex = 1;99}100else {101#ifndef IGNORE_ZERO_SIGN102if (sign)103*b++ = '-';104#endif105*b++ = '0';106*b = 0;107return b;108}109ex -= 0x3fff + 112;110mode = 2;111if (ndig <= 0) {112if (bufsize < 48)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