KittyCAD / modeling-app

The KittyCAD modeling app.
https://kittycad.io/modeling-app/download
MIT License
411 stars 35 forks source link

Multiplication of two large integer numbers have small floating point errors #1022

Open paultag opened 12 months ago

paultag commented 12 months ago

Given the following:

>>> 234567891 * 1234567891
289589986488187881

KCL evaluates to a close, but not identical, number

image

I reckon fixed point numbers are also floating point numbers - I'm filing this so I don't forget to look into this when I get some spare cycles

Irev-Dev commented 12 months ago

Good observation, you're probably right on the floating point thing.

At least that was definitely the case when the executor was written in TS, so likely is doing the same thing when it was ported to Rust.

alteous commented 12 months ago

I would bet it is due to 64 bit floating point numbers not being able to represent the number: reproducer

paultag commented 11 months ago

@alteous Ah yes, I had posted this elsewhere:

I /think/ my bug is that even ~fixed point numbers~ integers in KCL are floating point numbers, but I dropped this here so I don't forget to look into this tomorrow https://github.com/KittyCAD/modeling-app/issues/1022

After looking at it, I'm pretty sure integers are also floats in KCL, which I didn't realize!

lf94 commented 11 months ago

I'm surprised they aren't "BigNums" Curious to think about why they aren't "BigNums" - at the same time, f64 should be sufficient enough for any real world engineering case I would think (and if not, f128). The actual calculation though should be the exact same if they both follow the IEEE floating point standard.