lua-users home
lua-l archive

Re: Infinity as index

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


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

AltStyle によって変換されたページ (->オリジナル) /