Can anyone elaborate on the subject of syscalls/js
, why in line 57 there is a statement
if f != f { ... }
(f
is of type float64
).
How is it possible? When can a statement like i != i
be true
in go
?
Can anyone elaborate on the subject of syscalls/js
, why in line 57 there is a statement
if f != f { ... }
(f
is of type float64
).
How is it possible? When can a statement like i != i
be true
in go
?
For example if f
is of type float64
, and its value is a specific value representing "not a number", which you can get from math.NaN()
. NaN
–by definition–does not equal to any other float64
value, including NaN
itself. The float64
type uses the IEEE-754 standard which says only NaN
satisfies the f != f
unequality.
var f float64 = math.NaN()
fmt.Println(f != f)
This prints true
, try it on the Go Playground.
For reasoning, see What is the rationale for all comparisons returning false for IEEE754 NaN values?