Archived

This topic is now archived and is closed to further replies.

conversion from double to int..

This topic is 6021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?

Share this post


Link to post
Share on other sites
hmm no, cant do that, the values i use are angles and as the angles are in radians all of them (cept zero) have an infinte number of decimals.. well it might be possible to define a new angle-masurment system.. from -1024 to 2024 or sumthin hmm maybe its faster..

Share this post


Link to post
Share on other sites