OLD | NEW |
1 /**************************************************************** | 1 /**************************************************************** |
2 * | 2 * |
3 * The author of this software is David M. Gay. | 3 * The author of this software is David M. Gay. |
4 * | 4 * |
5 * Copyright (c) 1991, 1996 by Lucent Technologies. | 5 * Copyright (c) 1991, 1996 by Lucent Technologies. |
6 * | 6 * |
7 * Permission to use, copy, modify, and distribute this software for any | 7 * Permission to use, copy, modify, and distribute this software for any |
8 * purpose without fee is hereby granted, provided that this entire notice | 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 | 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 | 10 * or modification of this software and in all copies of the supporting |
(...skipping 28 matching lines...) Expand all Loading... |
39 if (!x) { | 39 if (!x) { |
40 *b++ = '0'; | 40 *b++ = '0'; |
41 *b = 0; | 41 *b = 0; |
42 goto done; | 42 goto done; |
43 } | 43 } |
44 #endif | 44 #endif |
45 s = s0 = dtoa(x, 0, 0, &decpt, &sign, &se); | 45 s = s0 = dtoa(x, 0, 0, &decpt, &sign, &se); |
46 if (sign) | 46 if (sign) |
47 *b++ = '-'; | 47 *b++ = '-'; |
48 if (decpt == 9999) /* Infinity or Nan */ { | 48 if (decpt == 9999) /* Infinity or Nan */ { |
49 » » while((*b++ = *s++)); | 49 » » while((*b++ = *s++)) {} |
50 goto done0; | 50 goto done0; |
51 } | 51 } |
52 if (decpt <= -4 || decpt > se - s + 5) { | 52 if (decpt <= -4 || decpt > se - s + 5) { |
53 *b++ = *s++; | 53 *b++ = *s++; |
54 if (*s) { | 54 if (*s) { |
55 *b++ = '.'; | 55 *b++ = '.'; |
56 while((*b = *s++)) | 56 while((*b = *s++)) |
57 b++; | 57 b++; |
58 } | 58 } |
59 *b++ = 'e'; | 59 *b++ = 'e'; |
60 /* sprintf(b, "%+.2d", decpt - 1); */ | 60 /* sprintf(b, "%+.2d", decpt - 1); */ |
61 if (--decpt < 0) { | 61 if (--decpt < 0) { |
62 *b++ = '-'; | 62 *b++ = '-'; |
63 decpt = -decpt; | 63 decpt = -decpt; |
64 } | 64 } |
65 else | 65 else |
66 *b++ = '+'; | 66 *b++ = '+'; |
67 » » for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); | 67 » » for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10) {} |
68 for(;;) { | 68 for(;;) { |
69 i = decpt / k; | 69 i = decpt / k; |
70 *b++ = i + '0'; | 70 *b++ = i + '0'; |
71 if (--j <= 0) | 71 if (--j <= 0) |
72 break; | 72 break; |
73 decpt -= i*k; | 73 decpt -= i*k; |
74 decpt *= 10; | 74 decpt *= 10; |
75 } | 75 } |
76 *b = 0; | 76 *b = 0; |
77 } | 77 } |
78 else if (decpt <= 0) { | 78 else if (decpt <= 0) { |
79 *b++ = '.'; | 79 *b++ = '.'; |
80 for(; decpt < 0; decpt++) | 80 for(; decpt < 0; decpt++) |
81 *b++ = '0'; | 81 *b++ = '0'; |
82 » » while((*b++ = *s++)); | 82 » » while((*b++ = *s++)) {} |
83 } | 83 } |
84 else { | 84 else { |
85 while((*b = *s++)) { | 85 while((*b = *s++)) { |
86 b++; | 86 b++; |
87 if (--decpt == 0 && *s) | 87 if (--decpt == 0 && *s) |
88 *b++ = '.'; | 88 *b++ = '.'; |
89 } | 89 } |
90 for(; decpt > 0; decpt--) | 90 for(; decpt > 0; decpt--) |
91 *b++ = '0'; | 91 *b++ = '0'; |
92 *b = 0; | 92 *b = 0; |
93 } | 93 } |
94 done0: | 94 done0: |
95 freedtoa(s0); | 95 freedtoa(s0); |
96 #ifdef IGNORE_ZERO_SIGN | 96 #ifdef IGNORE_ZERO_SIGN |
97 done: | 97 done: |
98 #endif | 98 #endif |
99 return b0; | 99 return b0; |
100 } | 100 } |
101 | 101 |
102 } // namespace dmg_fp | 102 } // namespace dmg_fp |
OLD | NEW |