aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-30 21:31:02 -0400
committerFeoramund <161657516+Feoramund@users.noreply.github.com>2024-06-30 22:18:25 -0400
commit8cd7fd95a37f1081cdbd011fd52bc4746fb21fd6 (patch)
tree2a96fa61031d9a592b0b79152c2c4ed57ec09232
parent13ace1dac9fbbd936907a5fc08604a6a24ef3d83 (diff)
Don't factor trailing zeroes into mantissa division
This should fix issues where `N00 / (pow+2)` results in a different number than `N / pow`.
-rw-r--r--core/strconv/strconv.odin22
1 files changed, 19 insertions, 3 deletions
diff --git a/core/strconv/strconv.odin b/core/strconv/strconv.odin
index 902f1cdc5..dce9f834a 100644
--- a/core/strconv/strconv.odin
+++ b/core/strconv/strconv.odin
@@ -932,6 +932,7 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
nd := 0
nd_mant := 0
decimal_point := 0
+ trailing_zeroes_nd := -1
loop: for ; i < len(s); i += 1 {
switch c := s[i]; true {
case c == '_':
@@ -947,9 +948,16 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
case '0' <= c && c <= '9':
saw_digits = true
- if c == '0' && nd == 0 {
- decimal_point -= 1
- continue loop
+ if c == '0' {
+ if nd == 0 {
+ decimal_point -= 1
+ continue loop
+ }
+ if trailing_zeroes_nd == -1 {
+ trailing_zeroes_nd = nd
+ }
+ } else {
+ trailing_zeroes_nd = -1
}
nd += 1
if nd_mant < MAX_MANT_DIGITS {
@@ -981,6 +989,14 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
if !saw_dot {
decimal_point = nd
}
+ if trailing_zeroes_nd > 0 {
+ trailing_zeroes_nd = nd_mant - trailing_zeroes_nd
+ }
+ for /**/; trailing_zeroes_nd > 0; trailing_zeroes_nd -= 1 {
+ mantissa /= base
+ nd_mant -= 1
+ nd -= 1
+ }
if base == 16 {
decimal_point *= 4
nd_mant *= 4