mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Don't factor trailing zeroes into mantissa division
This should fix issues where `N00 / (pow+2)` results in a different number than `N / pow`.
This commit is contained in:
@@ -932,6 +932,7 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
|
|||||||
nd := 0
|
nd := 0
|
||||||
nd_mant := 0
|
nd_mant := 0
|
||||||
decimal_point := 0
|
decimal_point := 0
|
||||||
|
trailing_zeroes_nd := -1
|
||||||
loop: for ; i < len(s); i += 1 {
|
loop: for ; i < len(s); i += 1 {
|
||||||
switch c := s[i]; true {
|
switch c := s[i]; true {
|
||||||
case c == '_':
|
case c == '_':
|
||||||
@@ -947,9 +948,16 @@ parse_f64_prefix :: proc(str: string) -> (value: f64, nr: int, ok: bool) {
|
|||||||
|
|
||||||
case '0' <= c && c <= '9':
|
case '0' <= c && c <= '9':
|
||||||
saw_digits = true
|
saw_digits = true
|
||||||
if c == '0' && nd == 0 {
|
if c == '0' {
|
||||||
decimal_point -= 1
|
if nd == 0 {
|
||||||
continue loop
|
decimal_point -= 1
|
||||||
|
continue loop
|
||||||
|
}
|
||||||
|
if trailing_zeroes_nd == -1 {
|
||||||
|
trailing_zeroes_nd = nd
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
trailing_zeroes_nd = -1
|
||||||
}
|
}
|
||||||
nd += 1
|
nd += 1
|
||||||
if nd_mant < MAX_MANT_DIGITS {
|
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 {
|
if !saw_dot {
|
||||||
decimal_point = nd
|
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 {
|
if base == 16 {
|
||||||
decimal_point *= 4
|
decimal_point *= 4
|
||||||
nd_mant *= 4
|
nd_mant *= 4
|
||||||
|
|||||||
Reference in New Issue
Block a user