lua-users home
lua-l archive

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


On Apr 24, 2014 12:15 PM, "Dirk Laurie" <dirk.laurie@gmail.com> wrote:
>
> 2014-04-24 1:19 GMT+02:00 Rena <hyperhacker@gmail.com>:
>
> > lua_isnan(L, n): returns true if the value at index n is NaN.
> > lua_isinfinity(L, n): returns 1 if the value at index n is infinity, -1 if the value is -infinity, and 0 otherwise.
>
> I don't think we need that at the C API level.
>
> In Lua, there are standard idioms:
>
> if x~=x then    -- x is NaN
>
> if 1/x == 0 then    -- x is inf or -inf
>
> if x==1/0 then    -- x is inf
>
> if x==-1/0 then   -- x is -inf
>
> if x==0 then   -- x is 0 or -0
>
> The hardest test of all is to distinguish between 0 and -0.
> If you can improve on the following, please post.
>
> if x==0 and 1/x>0 then -- x is 0
> if x==0 and 1/x<0 then -- x is -0
>

Sure, but string.sub is implemented in C.