lua-users home
lua-l archive

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


> lua_tounsigned does a cast from float to unsigned int. (I've
> compiled Lua to use float instead of double.) Casting a negative
> float value to unsigned int is undefined according to the C
> standard.
> 
> Does Lua really depend on the undefined behavior? Or is the test wrong.
> 
> In my case the test listed above fails with lua_tounsigned()
> returning 0 and (lua_Unsigned)-0x1234) returning 4294962636.

Neither. What is broken is the backup implementation of
lua_number2unsigned for non-double numbers. (The default implementation,
for doubles, does not do a cast from double to unsigned int.) You should
provide your own version of that macro.

-- Roberto