[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lua_number2int
- From: David Given <dg@...>
- Date: Wed, 15 Nov 2006 00:39:01 +0000
Brian Weed wrote:
[...]
> So, to be safe, maybe I should do this?
>
> #define lua_number2integer(i, d) ((d) < 0 ? (i) = (int)(d) : (i) =
> (int)(unsigned int)(d))
Actually, I think the only way to be completely safe would be to do:
int lua_number2integer_f(double d)
{
if (d < INT_MIN)
return INT_MIN;
if (d > INT_MAX)
return INT_MAX;
return (int)d;
}
#define lua_number2integer(i, d) i=lua_number2integer_f(d)
...but that's rather a mouthful, and of course you'd need a completely
separate version for unsigned ints.
--
╭─┈David Given┈──McQ─╮ "...electrons, nuclei and other particles are good
│┈ dg@cowlark.com┈┈┈┈│ approximations to perfectly elastic spherical
│┈(dg@tao-group.com)┈│ cows." --- David M. Palmer on r.a.sf.c
╰─┈www.cowlark.com┈──╯
Attachment:
signature.asc
Description: OpenPGP digital signature