When i am checking values inside scala interpreter like:
scala> 1==1.0000000000000001
res1: Boolean = true
scala> 1==1.000000000000001
res2: Boolean = false
Here I am not getting clear view related with “how does scala compiler interpret these as integer or floating points or doubles(and comparing)” .
It is not really Scala related, it is more of a ieee-754 floating-point arithmetic issue. First of all when comparing
IntwithDoubleit will castInttoDouble(always safe). The second case is obvious – values are different.What happens with the first case is that
Doubletype is not capable of storing that many significant digits (17 in your case, 64-bit floating point can store up-to 16 decimal digits) so it rounds the value to1. And1 == 1.