sosauce / CuteCalc

CuteCalc is a simple,lightweight and open-source calculator app for Android.
GNU General Public License v3.0
121 stars 9 forks source link

0.1 + 0.2 = 0.30000000000000004 #66

Closed realeatham closed 6 months ago

realeatham commented 6 months ago

Describe the bug See title

To Reproduce See title

Expected behavior The sum to equal 0.3

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

Additional context Could also be a problem with keval @notKamui

sosauce commented 6 months ago

https://discuss.kotlinlang.org/t/kotlin-compiler-apparently-losing-double-value-precision/14076

See this, I think it's "normal" and nothing we can do about it

sosauce commented 6 months ago

https://floating-point-gui.de/

sosauce commented 6 months ago

Oh wait, I could make it refactor or sum but do I really want to?

notKamui commented 6 months ago

@realeatham this is completely normal behavior for floating point arithmetic in binary representation. Please try that in many other languages and you'll see the same result.

@sosauce you should close this issue.

SlamaFR commented 6 months ago

@realeatham So this is basically a well known issue of floating point numbers in computer science.

See https://en.wikipedia.org/wiki/IEEE_754#Rounding_rules