diff options
| author | gingerBill <bill@gingerbill.org> | 2023-03-06 19:52:03 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2023-03-06 19:52:03 +0000 |
| commit | 1c2301e2f1fa22cdd1f45fb2d8824dd366836b50 (patch) | |
| tree | 823305f908fe60a6c77fb3633797ed57c1b3398b /src/exact_value.cpp | |
| parent | ef999f660b412d9eada0fffa644d3139186031a1 (diff) | |
Use `atof` in `float_from_string` to allow for debug C-like semantic purposes
Diffstat (limited to 'src/exact_value.cpp')
| -rw-r--r-- | src/exact_value.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/exact_value.cpp b/src/exact_value.cpp index 1ab50800d..7d5f71d78 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -1,4 +1,5 @@ #include <math.h> +#include <stdlib.h> gb_global BlockingMutex hash_exact_value_mutex; @@ -174,7 +175,36 @@ gb_internal ExactValue exact_value_integer_from_string(String const &string) { -gb_internal f64 float_from_string(String string) { +gb_internal f64 float_from_string(String const &string) { + if (string.len < 128) { + char buf[128] = {}; + isize n = 0; + for (isize i = 0; i < string.len; i++) { + u8 c = string.text[i]; + if (c == '_') { + continue; + } + if (c == 'E') { c = 'e'; } + buf[n++] = cast(char)c; + } + buf[n] = 0; + return atof(buf); + } else { + TEMPORARY_ALLOCATOR_GUARD(); + char *buf = gb_alloc_array(temporary_allocator(), char, string.len+1); + isize n = 0; + for (isize i = 0; i < string.len; i++) { + u8 c = string.text[i]; + if (c == '_') { + continue; + } + if (c == 'E') { c = 'e'; } + buf[n++] = cast(char)c; + } + buf[n] = 0; + return atof(buf); + } +/* isize i = 0; u8 *str = string.text; isize len = string.len; @@ -250,6 +280,7 @@ gb_internal f64 float_from_string(String string) { } return sign * (frac ? (value / scale) : (value * scale)); +*/ } gb_internal ExactValue exact_value_float_from_string(String string) { |