lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The following algorithm does it in any binary floating-point arithmetic.

x=1.0
repeat x=x+x until (2*x-1)%2 == 0
x=2*x-1
repeat x=x+x until 2*x==1/0



2017-08-31 21:39 GMT+02:00 Matthias Dörfelt <lists@mokafolio.de>:
> Hi,
>
> in C++ I often times use idioms like:
>
> auto shortestDistance = std::numeric_limits<float>::max()
> // …
> for(auto item : list)
> {
>         float dist = determineDistance(item);
>         if(dist < shortestDistance)
>         {
>                 // ...
>                 shortestDistance = dist;
>         }
> }
> // …
>
> After browsing for a while I could not find any similar constant to std::numeric_limits<float>::max() to get the biggest available number in lua. Is there one? If not, is there a reliable way to build my own function/constant?
>
> Thanks,
> Matthias