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

Ulf Wiger ulf@REDACTED
Mon Feb 27 18:34:51 CET 2012


Given that erlang terms have a total sort order, you can e.g. pick the atom 'infinity' as a value guaranteed to be larger than any int or float.

Alas, there is no data type smaller than a number. A way to cheat is to wrap numbers inside 1-tuples. Then, {} is guaranteed to be a lower bound (and [], or e.g. {infinity} could be an upper). Unfortunately, this has obvious performance consequences. :)

BR,
Ulf W

On 27 Feb 2012, at 18:07, Tom Burdick wrote:

> So in python and C to find the biggest and smallest number in a list
> of floating point numbers I'd do something like a lists:foldl and
> simply give it
> 
> inf and -inf respectively as the values to compare against, or better
> yet use some built in defines or variables defining what the min and
> max values for a particular number type are.
> 
> 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 or the maximal and
> minimal values for integers and floats in erlang? I didn't see it in
> my hunt around the documentation perhaps I just missed it.
> 
> Thanks!
> 
> Tom
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list