For your amusement, Go:
fmt.Print(0.3 == 0.1 + 0.2)
// => true
https://repl.it/repls/SubtleQuarrelsomeMaintenance fmt.Print(0.3 == 0.1 + 0.2)
// => true
https://repl.it/repls/SubtleQuarrelsomeMaintenanceWhy does it have this result?
Yes. The behaviour is quite odd and unexpected. It seems they have different rules for when to apply the constant version of floating math than what constitutes actual compile time evaluation.
const a float64 = 0.1;
const b float64 = 0.2;
const x float64 = 0.1 + 0.2; // Const evaluation, "rational" math
const y float64 = a + b; // Const evaluation, IEEE-754 math
fmt.Println(x == y) // false ??!?
This seems quite a horrible approach.EDIT: Or how about this one:
const x float64 = 0;
fmt.Println(x + 0.1 + 0.2 == 0.1 + 0.2 + x ); // false!
fmt.Println(x + 0.1 + 0.2 == x + (0.1 + 0.2) ); // false!Go: Here's a trivial example.