[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Re: Lua with ints and floats**
**From**: "Nick Trout" <nick@...>
**Date**: Mon, 10 Jul 2000 16:32:30 +0100

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
doubles.
Bye
Mauro