#### Archived

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

# Making a faster cosf, and sinf function?

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

## Recommended Posts

Does anyone have a accuate yet fast cosf and sinf function? I just was wondering cuz i could just maybe add it to make things a bit faster sense speed in games is always an issue

##### Share on other sites
Try using look up tables. Personally, I like to use arrays with 3600 values or so and precompute the values.

My Website

##### Share on other sites
quote:
Original post by Foxostro
Try using look up tables. Personally, I like to use arrays with 3600 values or so and precompute the values.

Sizing your table to be a power of two makes better sense. Remember that dividing a circle in ''360 degrees'' is a completely arbitrary decision.

“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan (C programming language co-inventor)

##### Share on other sites
Also, if you weren''t exactly going for accuracy, you could always break it down into the Taylor Polynomials around whichever point was closest to you.... for some points (pi/3, for example) a linear approximation does wonders.

##### Share on other sites
quote:
Original post by Foxostro
Try using look up tables. Personally, I like to use arrays with 3600 values or so and precompute the values.

Way to kill the cache. A 14K lookup table sounds like a bad idea to me... Anyway I would recommend the taylor-series approimations (you can find them everywhere). To seven powers should give you accuracy in the range [0, 2 * pi) that is good enough for government work.

##### Share on other sites
For source code to a good and fast approximation, look a Magic Software''s free math lib. Works wonders for me

Sander Maréchal

__asm fsincos

##### Share on other sites
Try searching the forum.

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633665
• Total Posts
3013245
×