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

Matthew Evans mattevans123@REDACTED
Mon Feb 27 18:41:15 CET 2012

```Good point....my excuse is my daughter was up all night :)

From: hakan.nilsson@REDACTED
Date: Mon, 27 Feb 2012 18:37:25 +0100
Subject: Re: [erlang-questions] Inf, NaN, and -Inf
To: mattevans123@REDACTED
CC: thomas.burdick@REDACTED; erlang-questions@REDACTED

Why would you do it with a complicated foldl instead of just lists:max(List) and lists:min(List)?
On Mon, Feb 27, 2012 at 6:26 PM, Matthew Evans <mattevans123@REDACTED> wrote:

You can use lists:sort/1
> List = [7.1,2.2,1.1,5.7,2].

[7.1,2.2,1.1,5.7,2]2> Sorted = lists:sort(List).[1.1,2,2.2,5.7,7.1]3> hd(Sorted).1.14> lists:last(Sorted).7.1

Or using lists:fold/3:
5> lists:foldl(fun(Val,{Min,Max}) -> {erlang:min(Val,Min),erlang:max(Val,Max)} end, {erlang:hd(List),erlang:hd(List)}, List++[2.1]).

{1.1,7.1}
Matt----------------------------------------
> Date: Mon, 27 Feb 2012 11:07:53 -0600
> From: thomas.burdick@REDACTED

> To: erlang-questions@REDACTED
> Subject: [erlang-questions] Inf, NaN, and -Inf
>
> 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

_______________________________________________

erlang-questions mailing list

erlang-questions@REDACTED

http://erlang.org/mailman/listinfo/erlang-questions

--
Håkan Nilsson
Klarna AB
Norra Stationsgatan 61
SE-113 43 Stockholm

Tel: +46 (0)8 120 120 00
Dir: +46 (0)70 00 127 07

Fax: +46 (0)8 120 120 99
Web: www.klarna.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120227/35b2e835/attachment.htm>
```