[erlang-questions] Inf, NaN, and -Inf

Peer Stritzinger <>
Mon Feb 27 22:47:07 CET 2012


On Mon, Feb 27, 2012 at 9:47 PM, Richard O'Keefe <> wrote:
>> Is there some sane way to do this in erlang? Is there a way to get the
>> floating point values inf and -inf in erlang
>
> I haven't found one.  Somebody might want to write an EEP recommending
> richer access to IEEE arithmetic features.  (Is anyone running Erlang
> on z/Series?)

Its worse than I thought: even building a binary for e.g. +Inf and
matching it as float doesn't work

    1> <<F:32/float>> = <<0:1, 255:8, 0:23>>.
    ** exception error: no match of right hand side value <<127,128,0,0>>

This looks like an effort was made not having the value Inf in the system ever.

Overflowing a operation doesn't work either (gives a badarg).

The failure of the pattern matching is not very nice if one wants to
use it to read binary floating point streams (which might be argued
one shouldn't).

Could a NIF be build to grandfather the forbidden values in?

Is the runtime somehow built around assumptions that Inf and NaN never
occur as values?

-- Peer



More information about the erlang-questions mailing list