From ad17de58116c4019742400c5e333eb801df45103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 17 Jun 2017 16:50:09 -0700 Subject: [PATCH] Cleanup. --- include/bx/string.h | 2 +- src/dtoa.cpp | 32 ++++++++++++++------------------ tests/string_test.cpp | 8 ++++++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/bx/string.h b/include/bx/string.h index 447edf4..d1fae26 100644 --- a/include/bx/string.h +++ b/include/bx/string.h @@ -240,7 +240,7 @@ namespace bx int32_t toString(char* _out, int32_t _max, uint64_t _value, uint32_t _base = 10); /// - double fromString(const char* _str); + bool fromString(double* _out, const char* _str); } // namespace bx diff --git a/src/dtoa.cpp b/src/dtoa.cpp index 6b96c06..e63596b 100644 --- a/src/dtoa.cpp +++ b/src/dtoa.cpp @@ -707,7 +707,7 @@ namespace bx #define GETC(s) *s++ - static int parser(const char *s, struct PrepNumber *pn) + static int parser(const char *s, PrepNumber *pn) { int state = FSM_A; int digx = 0, c = ' '; /* initial value for kicking off the state machine */ @@ -921,10 +921,10 @@ namespace bx return result; } - static double converter(struct PrepNumber *pn) + static double converter(PrepNumber *pn) { int binexp = 92; - union HexDouble hd; + HexDouble hd; uint32_t s2, s1, s0; /* 96-bit precision integer */ uint32_t q2, q1, q0; /* 96-bit precision integer */ uint32_t r2, r1, r0; /* 96-bit precision integer */ @@ -1037,47 +1037,43 @@ namespace bx return hd.d; } - double fromString(const char* _str) + bool fromString(double* _out, const char* _str) { - struct PrepNumber pn; - union HexDouble hd; - int i; - double result; - + PrepNumber pn; pn.mantissa = 0; pn.negative = 0; pn.exponent = 0; + + HexDouble hd; hd.u = DOUBLE_PLUS_ZERO; - i = parser(_str, &pn); - - switch (i) + switch (parser(_str, &pn) ) { case PARSER_OK: - result = converter(&pn); + *_out = converter(&pn); break; case PARSER_PZERO: - result = hd.d; + *_out = hd.d; break; case PARSER_MZERO: hd.u = DOUBLE_MINUS_ZERO; - result = hd.d; + *_out = hd.d; break; case PARSER_PINF: hd.u = DOUBLE_PLUS_INFINITY; - result = hd.d; + *_out = hd.d; break; case PARSER_MINF: hd.u = DOUBLE_MINUS_INFINITY; - result = hd.d; + *_out = hd.d; break; } - return result; + return true; } } // namespace bx diff --git a/tests/string_test.cpp b/tests/string_test.cpp index 4f5d374..1a361c7 100644 --- a/tests/string_test.cpp +++ b/tests/string_test.cpp @@ -186,8 +186,12 @@ static bool testFromString(double _value, const char* _input) { char tmp[1024]; int32_t num = bx::toString(tmp, BX_COUNTOF(tmp), _value); - const double lhs = bx::fromString(tmp); - const double rhs = bx::fromString(_input); + + double lhs; + bx::fromString(&lhs, tmp); + + double rhs; + bx::fromString(&rhs, _input); if (lhs == rhs) {