0

I'm trying to make an addition of the 2 following numbers:

v1 = 0.005919725632510221
v2 = 0.9940802743674898

v1+v2 

Result always = 1

Why ?

wawanopoulos
  • 9,614
  • 31
  • 111
  • 166
  • The difference between their values and 1 is too small to be represented. If both numbers started out, say, 10^20 times larger than they are currently, you could use BigInt. (maybe there's a library for decimal manipulation too) – CertainPerformance Sep 20 '19 at 07:45
  • Re "always" -- if you repeat the same operation, of course you're going to get the same result. As for why adding those numbers gives you 1, see the [linked question](https://stackoverflow.com/questions/588004/is-floating-point-math-broken)'s answers. – T.J. Crowder Sep 20 '19 at 07:45
  • Just for the curious the result is: `1.000000000000000021` – Roland Starke Sep 20 '19 at 07:51
  • @RolandStarke - You mean mathematically, right? Because it exceeds the precision of IEEE-754 double-precision floating point. The value is actually 1 in IEEE-754 double-precision floating point, not just a number very near 1. – T.J. Crowder Sep 20 '19 at 08:25
  • @T.J.Crowder Mm yes sry, meant mathematically. (Now that you say it, i just add confusion and waste peoples time.) – Roland Starke Sep 20 '19 at 08:33
  • @RolandStarke - That's a bit harsh. :-) Have a good one! – T.J. Crowder Sep 20 '19 at 08:52

0 Answers0