eva icon indicating copy to clipboard operation
eva copied to clipboard

Precision problem with floating points numbers

Open snpefk opened this issue 5 years ago • 6 comments

Hi! Less words, more example. When I'm trying to add up 41.90 + 91.90 + 209 + 249 eva gave a 591.7999999999, although I expected 591.80.

snpefk avatar Jan 03 '20 19:01 snpefk

noted. eva uses rust's floating point arithmetic, we should definitely move over to fixed point arithmetic.

oppiliappan avatar Jan 05 '20 16:01 oppiliappan

I'm not a big expert in computer arithmetic, but my research (a.k.a browsing Wikipedia) suggest to look at "Arbitrary-precision arithmetic" since bc use similar approach.

rug seems like a nice choice. It's implement Integer, Rational and Float and configurable (you can turn off Complex numbers). The only drawback I found was the dependence on GNU libraries.

snpefk avatar Jan 09 '20 12:01 snpefk

I recently just noticed this issue, isn't num solving this? I think it's num_rational that provides arbitrary precision.

pickfire avatar Oct 12 '20 10:10 pickfire

@pickfire I am afraid I never got around to actually implementing it (I imported the num crate and completely forgot about it soon after)

oppiliappan avatar Oct 14 '20 17:10 oppiliappan

@NerdyPepper Heh, you could make this a hacktoberfest issue and hope someone solve it.

pickfire avatar Oct 15 '20 03:10 pickfire

In Excel, i have these 591.800000000000068. Relative failure of 1.15E-16. Welcome in the real world ;-)

JensGrabner avatar Oct 18 '20 20:10 JensGrabner

Running cargo r on the master branch works fine for me:

image

TheTechRobo avatar Oct 02 '22 02:10 TheTechRobo

The display is fixed in master branch, but still it doesn't support numbers larger than f64, I guess this can be closed for now.

pickfire avatar Oct 02 '22 09:10 pickfire