1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A/* Convert a floating point value to ASCII. 1N/A** Written by Kiem-Phong Vo and Glenn Fowler (SFFMT_AFORMAT) 1N/Achar*
buf;
/* conversion goes here */ 1N/Aint*
decpt;
/* to return decimal point */ 1N/Aint*
len;
/* return string length */ 1N/A static char lx[] =
"0123456789abcdef";
1N/A static char ux[] =
"0123456789ABCDEF";
1N/A while ((x -=
4) >= 0)
1N/A {
/* scale to a small enough number to fit an int */ 1N/A else if(f >
0.0 && f <
0.1)
1N/A {
/* scale to avoid excessive multiply by 10 below */ 1N/A {
/* translate the integer part */ 1N/A /* remaining number of digits to compute; add 1 for later rounding */ 1N/A while((
long)(d = f*
10.) == 0)
1N/A {
/* generate fractional digits */ 1N/A {
/* fill with 0's */ 1N/A else if((n = (
long)(f *=
10.)) <
10)
1N/A {
double f = *(
double*)
vp;
1N/A while ((x -=
4) >= 0)
1N/A {
/* scale to a small enough number to fit an int */ 1N/A else if(f >
0.0 && f <
1e-8)
1N/A {
/* scale to avoid excessive multiply by 10 below */ 1N/A {
/* translate the integer part */ 1N/A /* remaining number of digits to compute; add 1 for later rounding */ 1N/A while((
long)(d = f*
10.) == 0)
1N/A {
/* generate fractional digits */ 1N/A {
/* fill with 0's */ 1N/A else if((n = (
long)(f *=
10.)) <
10)
1N/A { *
sp++ = (
char)(
'0' + n);
1N/A {
/* round the last digit */ 1N/A {
/* next power of 10 */ 1N/A {
/* add one more 0 for %f precision */ 1N/A if (((m >> x) &
0xf) >=
8)