-1

I understand 0.3 does not have an accurate binary representation. Suppose I run the following code:

enter image description here

Why is the answer "True" in the first case and "False" in the second? Shouldn't both be false?

D.W.
  • 167,959
  • 22
  • 232
  • 500

1 Answers1

2

They “should” nothing. Double precision arithmetic will round the mantissa to 53 bits. The numbers involved will be rounded in ways that are hard to predict, and then all the information about the rounding is lost.

Sometimes two numbers that should be mathematically equal but were calculated in different ways are rounded the same way, sometimes they are not. Hard to predict. So sometimes the rounded numbers are the same, sometimes they are not.

gnasher729
  • 32,238
  • 36
  • 56