/****************************************************************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#endif43#ifdef IEEE_808744#define _0 245#define _1 146#define _2 047#endif4849char*50#ifdef KR_headers51g_xLfmt(buf, V, ndig, bufsize) char *buf; char *V; int ndig; size_t bufsize;52#else53g_xLfmt(char *buf, void *V, int ndig, size_t bufsize)54#endif55{56static FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, 0 };57char *b, *s, *se;58ULong bits[2], *L, sign;59int decpt, ex, i, mode;60#ifdef Honor_FLT_ROUNDS61#include "gdtoa_fltrnds.h"62#else63#define fpi &fpi064#endif6566if (ndig < 0)67ndig = 0;68if (bufsize < ndig + 10)69return 0;7071L = (ULong*)V;72sign = L[_0] & 0x80000000L;73bits[1] = L[_1];74bits[0] = L[_2];75if ( (ex = (L[_0] >> 16) & 0x7fff) !=0) {76if (ex == 0x7fff) {77/* Infinity or NaN */78if (bits[0] | bits[1])79b = strcp(buf, "NaN");80else {81b = buf;82if (sign)83*b++ = '-';84b = strcp(b, "Infinity");85}86return b;87}88i = STRTOG_Normal;89}90else if (bits[0] | bits[1]) {91i = STRTOG_Denormal;92}93else {94b = buf;95#ifndef IGNORE_ZERO_SIGN96if (sign)97*b++ = '-';98#endif99*b++ = '0';100*b = 0;101return b;102}103ex -= 0x3fff + 63;104mode = 2;105if (ndig <= 0) {106if (bufsize < 32)107return 0;108mode = 0;109}110s = gdtoa(fpi, ex, bits, &i, mode, ndig, &decpt, &se);111return g__fmt(buf, s, se, decpt, sign, bufsize);112}113114115