#### Archived

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

# conversion from double to int..

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

## 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 on other sites
int integer;
integer = (int)(value + 0.5);

ok cool thanks

##### Share on other sites
Why not store the integers in the array.
You then need the conversion only at initialization.

##### 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..

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5

• 14
• 39
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631717
• Total Posts
3001878
×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!