lua-users home
lua-l archive

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

Using 5.3 with #define LUA_INT_INT:

return math.pow(2,31)>>0
stdin:1: number has no integer representation
stack traceback:
  stdin:1: in main chunk
  [C]: in ?

To get integer anyway, with wraparound as it should be, ie equivalent of
int32_t i = (int64_t)d in C, one can:

string.format("%.0f", math.pow(2,31))>>0

This gives the correct result, but feels somewhat kludgy taking the detour
via string. Does anyone know of a better way?

Use case: Mixing FP math and bitwise ops, for example SHA256 [1]