7 // #include <msvcrt/locale.h>
9 // replace fjgpp fcvtbuf from project http://www.jbox.dk/sanos/source/lib/fcvt.c.html
10 // with small modification's to match ReactOS arch
12 // Floating point to string conversion routines
14 // Copyright (C) 2002 Michael Ringgaard. All rights reserved.
16 // Redistribution and use in source and binary forms, with or without
17 // modification, are permitted provided that the following conditions
20 // 1. Redistributions of source code must retain the above copyright
21 // notice, this list of conditions and the following disclaimer.
22 // 2. Redistributions in binary form must reproduce the above copyright
23 // notice, this list of conditions and the following disclaimer in the
24 // documentation and/or other materials provided with the distribution.
25 // 3. Neither the name of the project nor the names of its contributors
26 // may be used to endorse or promote products derived from this software
27 // without specific prior written permission.
29 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
30 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
33 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #define CVTBUFSIZE 2 * DBL_MAX_10_EXP + 10
45 static char *cvt(double arg
, int ndigits
, int *decpt
, int *sign
, char *buf
, int eflag
)
51 if (ndigits
>= CVTBUFSIZE
- 1) ndigits
= CVTBUFSIZE
- 2;
61 p1
= &buf
[CVTBUFSIZE
];
65 p1
= &buf
[CVTBUFSIZE
];
68 fj
= modf(fi
/ 10, &fi
);
69 *--p1
= (int)((fj
+ .03) * 10) + '0';
72 while (p1
< &buf
[CVTBUFSIZE
]) *p
++ = *p1
++;
76 while ((fj
= arg
* 10) < 1)
83 if (eflag
== 0) p1
+= r2
;
90 while (p
<= p1
&& p
< &buf
[CVTBUFSIZE
])
94 *p
++ = (int) fj
+ '0';
96 if (p1
>= &buf
[CVTBUFSIZE
])
98 buf
[CVTBUFSIZE
- 1] = '\0';
114 if (p
> buf
) *p
= '0';
123 char *fcvtbuf(double arg
, int ndigits
, int *decpt
, int *sign
, char *buf
)
125 return cvt(arg
, ndigits
, decpt
, sign
, buf
, 0);