I’m trying to have an Elixir library represent the “NaN” value.
Currently, it uses the :nan atom, but it confuses other libraries that expect floating point numbers, and I don’t know what the “proper” way to express the value.
I could not find a
Float.nan function, is there supposed to be one somewhere else ?
The BEAM does not know about NaNs and infinity (in terms of a float value), so if you really need them, you’ll need to wrap in a type of your own.
As @NobbZ said, Erlang do not support NaNs and infinities. It is just impossible to create them, just check this out:
<<f::float-size(32)>> = <<0::size(1), 0xff::size(8), 1::size(23)>>
Will fail match as the value set on the right hand of the match is IEEE 754 qNaN (on ARM and x86) which is not proper 32 bit float in Erlang.