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

Matthew Evans mattevans123@REDACTED
Mon Feb 27 18:28:01 CET 2012



Obviously, on the lists:foldl you don't need to do ++[2.1] at the end ;)

From: mattevans123@REDACTED
To: thomas.burdick@REDACTED; erlang-questions@REDACTED
Date: Mon, 27 Feb 2012 12:26:41 -0500
Subject: Re: [erlang-questions] Inf, NaN, and -Inf








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 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20120227/bb929df3/attachment.htm>


More information about the erlang-questions mailing list