Function to simulate int32 wrapping
planned
Tapple Gao
Please add a function that converts a float64 to a signed 32-bit integer, compatable with lsl. It would be equivilant to
in luau:
function bit32.s32(n: number)
return (math.modf(n) + 0x8000_0000) % 0x1_0000_0000 - 0x8000_0000
end
in c:
double s32(double n) {
return (double)(s32)n;
}
Code that dealt with integers
>= 0x8000_0000
behave differently in lsl and luau, due to s32 wrapping. I imagine there's already a function like this for the lsl compiler, but exposing it to slua scripters would be helpful for converting old scriptsLog In
H
Harold Linden
marked this post as
planned
Thanks! I'll get this in. The C++ implementation may be more subtle since you don't really want clamping there and float->int casts outside of int range are Undefined Behavior in C++ as I've recently come to learn. Something more like the Lua version should work well.