lua-users home
lua-l archive

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

But the question was how do you shift floats? (a bit pedantic but floats arent
integers) It only becomes an integer when you need it as such eg. if you assign
the float to an integer variable. And you'd have to do: floor(x)*2.f as
floor(x*2.f) would include the fractional bit assuming you were simulating
integers. (imagine shifting 1.5)

(x *= .5f // >>1, would be quicker still)

> float x = 5.f;
> x *= 2.f; // <<1
> x /= 2.f; // >>1
> Would be quickest!
But you must add floor() to cut off the decimal part:
x = floor(x * 2.f);
x = floor(x / 2.f);
And you should check if the new x is > 2^16 or 2^32.

I convert doubles to ulong, shift, and then convert them back to