<div>Why would you do it with a complicated foldl instead of just lists:max(List) and lists:min(List)?</div><div><br></div><div>On Mon, Feb 27, 2012 at 6:26 PM, Matthew Evans <span dir="ltr"><<a href="mailto:mattevans123@hotmail.com">mattevans123@hotmail.com</a>></span> wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div dir="ltr">
<div><font face="'Lucida Console'"><br></font></div><div><font face="'Lucida Console'">You can use lists:sort/1</font></div><div style="font-family:'Lucida Console'"><br></div><div>> List = [7.1,2.2,1.1,5.7,2].</div>
<div>[7.1,2.2,1.1,5.7,2]</div><div>2> Sorted = lists:sort(List).</div><div>[1.1,2,2.2,5.7,7.1]</div><div>3> hd(Sorted).</div><div>1.1</div><div><div>4> lists:last(Sorted).</div><div>7.1</div></div><div><br></div>
<div>Or using lists:fold/3:</div><div><br></div><div><div>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]). </div><div>
{1.1,7.1}</div></div><div><br></div><div>Matt</div>----------------------------------------<br>> Date: Mon, 27 Feb 2012 11:07:53 -0600<br>> From: <a href="mailto:thomas.burdick@gmail.com" target="_blank">thomas.burdick@gmail.com</a><br>
> To: <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>> Subject: [erlang-questions] Inf, NaN, and -Inf<div><div class="h5"><br>><br>> So in python and C to find the biggest and smallest number in a list<br>
> of floating point numbers I'd do something like a lists:foldl and<br>> simply give it<br>><br>> inf and -inf respectively as the values to compare against, or better<br>> yet use some built in defines or variables defining what the min and<br>
> max values for a particular number type are.<br>><br>> Is there some sane way to do this in erlang? Is there a way to get the<br>> floating point values inf and -inf in erlang or the maximal and<br>> minimal values for integers and floats in erlang? I didn't see it in<br>
> my hunt around the documentation perhaps I just missed it.<br>><br>> Thanks!<br>><br>> Tom<br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br> </div></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote><br><br clear="all"><br>-- <br><div>Håkan Nilsson</div><div style="text-align:left"><br>Klarna AB<br> Norra Stationsgatan 61<br> SE-113 43 Stockholm<br><br> Tel: +46 (0)8 120 120 00<br>Dir: +46 (0)70 00 127 07<br>
Fax: +46 (0)8 120 120 99<br> Web: <a href="http://www.klarna.com" target="_blank">www.klarna.com</a><br></div><div style="text-align:left"><br></div><div style="text-align:left"><img src="http://www.klarna.com/klarna-signatur.jpg"><br>
</div><br>