summaryrefslogtreecommitdiff
path: root/dtoa.c
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-12-29 23:03:58 +1030
committerMark Pulford <mark@kyne.com.au>2012-03-04 18:54:34 +1030
commitca42b9a996f9046ba3876ad8a81cda1d935b39cf (patch)
tree229cc0e408e28abc882778c68496c87af0d781ba /dtoa.c
parent8eecc878e0560461ef42bd3cd8d6dfe33cf148e8 (diff)
downloadlua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.tar.gz
lua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.tar.bz2
lua-cjson-ca42b9a996f9046ba3876ad8a81cda1d935b39cf.zip
Use internal dtoa/strtod for double conversion
The internal Lua CJSON dtoa/strtod routines have locale support disabled. This avoids problems under locales with comma decimal separators. Build changes: - CMake: Check for big endian architectures - Makefile: Provide option to build with dtoa.c Modifications to dtoa.c: - Include locale dtoa_config.h configuration - Rename Infinity/NaN to inf/nan to match common C libraries - Rename strtod() -> internal_strtod() to prevent conflict with libc function Modifications to g_fmt.c: - Return output string length (instead of original buffer pointer) - Provide precision as an argument to g_fmt() - Silence compilations warnings from vendor source - while(a = b) - Unused label "done:" - Only swap to scientific notation when once the number of decimal digits required exceeds the precision available. This matches standard printf format %g. - Display a "0" in front of numbers < 1.
Diffstat (limited to 'dtoa.c')
-rw-r--r--dtoa.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/dtoa.c b/dtoa.c
index 4a458a4..520926c 100644
--- a/dtoa.c
+++ b/dtoa.c
@@ -185,6 +185,8 @@
185 * used for input more than STRTOD_DIGLIM digits long (default 40). 185 * used for input more than STRTOD_DIGLIM digits long (default 40).
186 */ 186 */
187 187
188#include "dtoa_config.h"
189
188#ifndef Long 190#ifndef Long
189#define Long long 191#define Long long
190#endif 192#endif
@@ -523,7 +525,7 @@ BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflc
523#define Kmax 7 525#define Kmax 7
524 526
525#ifdef __cplusplus 527#ifdef __cplusplus
526extern "C" double strtod(const char *s00, char **se); 528extern "C" double fpconv_strtod(const char *s00, char **se);
527extern "C" char *dtoa(double d, int mode, int ndigits, 529extern "C" char *dtoa(double d, int mode, int ndigits,
528 int *decpt, int *sign, char **rve); 530 int *decpt, int *sign, char **rve);
529#endif 531#endif
@@ -2471,7 +2473,7 @@ retlow1:
2471#endif /* NO_STRTOD_BIGCOMP */ 2473#endif /* NO_STRTOD_BIGCOMP */
2472 2474
2473 double 2475 double
2474strtod 2476fpconv_strtod
2475#ifdef KR_headers 2477#ifdef KR_headers
2476 (s00, se) CONST char *s00; char **se; 2478 (s00, se) CONST char *s00; char **se;
2477#else 2479#else
@@ -3746,9 +3748,9 @@ dtoa
3746 *decpt = 9999; 3748 *decpt = 9999;
3747#ifdef IEEE_Arith 3749#ifdef IEEE_Arith
3748 if (!word1(&u) && !(word0(&u) & 0xfffff)) 3750 if (!word1(&u) && !(word0(&u) & 0xfffff))
3749 return nrv_alloc("Infinity", rve, 8); 3751 return nrv_alloc("inf", rve, 8);
3750#endif 3752#endif
3751 return nrv_alloc("NaN", rve, 3); 3753 return nrv_alloc("nan", rve, 3);
3752 } 3754 }
3753#endif 3755#endif
3754#ifdef IBM 3756#ifdef IBM