1 /****************************************************************
3 * The author of this software is David M. Gay.
5 * Copyright (c) 1991, 1996 by Lucent Technologies.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose without fee is hereby granted, provided that this entire notice
9 * is included in all copies of any software which is or includes a copy
10 * or modification of this software and in all copies of the supporting
11 * documentation for such software.
13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
14 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY
15 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
16 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
18 ***************************************************************/
20 /* g_fmt(buf,x) stores the closest decimal approximation to x in buf;
21 * it suffices to declare buf
30 g_fmt(register char *b, double x)
38 #ifdef IGNORE_ZERO_SIGN
45 s = s0 = dtoa(x, 0, 0, &decpt, &sign, &se);
48 if (decpt == 9999) /* Infinity or Nan */ {
49 while((*b++ = *s++)) {}
52 if (decpt <= -4 || decpt > se - s + 5) {
60 /* sprintf(b, "%+.2d", decpt - 1); */
67 for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10) {}
78 else if (decpt <= 0) {
80 for(; decpt < 0; decpt++)
82 while((*b++ = *s++)) {}
87 if (--decpt == 0 && *s)
90 for(; decpt > 0; decpt--)
96 #ifdef IGNORE_ZERO_SIGN
102 } // namespace dmg_fp