conversion from double to int..
Just a little background :
ive made a sinus[ 2048 ] array, and i''m gonna use it instead of the sin() function to gain speed
( forexample sinus[ 1024 ] = 1 instead of sin( pi/2 ) = 1 )
I use it in a function, when e.g. the value "value" is passed, it divides "value" by 3.1415.... and multiplies it with 2048 to get the right place in the array
Before i can "return sinus[ value ];" i have to convert value to an integer value.. and i need to do it as fast as possible.
Ive come up with this thing:
int integer = 0;
while( integer < value )
{
integer++
}
if( ( integer - value ) > 0.5 )
{
integer -= 1;
}
... but since the array is quite large this operation might take a lot of time ( especially since i might need to make it even larger )
does anyone know of a faster way to convert it/ find the closest integer ?
Why not store the integers in the array.
You then need the conversion only at initialization.
You then need the conversion only at initialization.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement