odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.13k stars 551 forks source link

Don't factor trailing zeroes into mantissa division #3849

Closed Feoramund closed 5 days ago

Feoramund commented 6 days ago

This should fix issues where N00 / (pow+2) results in a different number than N / pow.

@karl-zylinski Would you be able to try this out and let me know if it resolves your issue with floating point precision loss from #3847?

karl-zylinski commented 5 days ago

This resolves my issues. Thank you so much! You're such a great contributor to this project!

For reference, this program:

v: f64 = 1
b := strings.builder_make()
strings.write_f64(&b, v, 'f')
vs := strings.to_string(b)
vv, _ := strconv.parse_f64(vs)
fmt.println(vv)

outputs 1.976262583364986e-308 without these changes. With these changes it outputs just 1.

Similarly, with v: f64 = 1.2 it outputs 1.1102230246251565 without these changes. But with these changes it outputs a perfect 1.2.

✨✨✨✨