I try to get 2.4/0.8 == 3 in Go
w:=float64(2.4)
fmt.Println(math.Floor(w/0.8),math.Floor(2.4/0.8) )
It gives me "2 3".
The question is why math.Floor(w/0.8)
won't give me 3. Is it the precision limit of float number?
The program output is correct. The representation of many real numbers in the IEEE format is not precise. The first number is actually (in the limited 64 bits version of it) less than 3 so floor returns '2' correctly. The second one is computed at compile time using greater precision.
Recomended reading.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With