Fast and accurate sine/cosine
#41
Posted 07 August 2007 - 09:26 AM
Do a search for MinMax polynomials. These give you the best approximation.
This stuff here is a must read as well: http://www.research....-functions.html
My stuff: torus.untergrund.net <-- some diy electronic stuff and more.
#42
Posted 07 August 2007 - 12:03 PM
iMalc said:
For other situations the more generic minimax algorithm can give excellent results. If you want a Real Challenge™ though try finding a fast approximation for pow and then share it with me. ;)
You might also be interested in this thread: Approximate Math Library.
#43
Posted 13 November 2007 - 05:20 PM
Q = (3150/(pi^3)) - (30240/(pi^5)) - 2
#44
Posted 22 November 2007 - 11:59 AM
(Your Q=0.775160898644)
#45
Posted 29 November 2007 - 11:05 AM
#46
Posted 29 November 2007 - 02:34 PM
Please check out the original formula from Nick (first post on page 1). BTW, the external images of his post do not work anymore. Too sad...
#47
Posted 29 November 2007 - 03:55 PM
roosp said:
#48
Posted 30 November 2007 - 10:14 AM
roosp said:
Please check out the original formula from Nick (first post on page 1). BTW, the external images of his post do not work anymore. Too sad...
Yeah, I know that. I think I didn't express myself correctly.
I want to know how to find (with maths) P (or Q) that minimizes the absolute error and the relative one.
#49
Posted 30 November 2007 - 10:15 AM
Nick said:
I can host the images if you want.
#50
Posted 30 November 2007 - 10:27 AM
yashez said:
#51
Posted 30 November 2007 - 01:37 PM
yashez said:
I want to know how to find (with maths) P (or Q) that minimizes the absolute error and the relative one.
I got the values from this website http://fastsine.tripod.com
Error plots and some code. Excellent list with references.
#52
Posted 02 December 2007 - 09:16 PM
#53
Posted 16 December 2007 - 05:35 PM
Originally I calculated values for a generic degree 4 polynomial, but I like symmetry, so all the formulas that follow are symmetric around pi/2.
Starting with minimizing absolute error we get
~ 0.985893x + 0.052042 x^2 - 0.232915 x^3 + 0.037069 x^4
minimizing relative error
~ 0.983251 x + 0.056247 x^2 - 0.235056 x^3 + 0.037410 x^4
minimizing maximum error
~ 0.988023 x + 0.048651 x^2 - 0.231188 x^3 + 0.036795 x^4
And a graph of the errors over the range [0, pi]
green - min absolute error
blue - min maximum error
magenta - min relative error
red - nick's formula

Then I also calculated some more... so another graph
green, blue, magenta, red - same as above
black - min absolute error of the derivatives
yellow - min sum of absolute error and absolute error of the derivatives
cyan - min square of the error

And, an interesting note, nick's formula intersects sin(x) at pi/6 and 5*pi/6.
#54
Posted 16 December 2007 - 06:51 PM
EDIT: corrected.
#55
Posted 26 January 2009 - 07:22 AM
I know this is an old post but I just wanted you to know it has really saved my bacon. I've been struggling with a high speed motor control loop and needed a fast sincos().
I'm running on a Luminary Micro at 50MHz. The gcc sincos (presumably taylor series) ran in 104uS. Your polynomial approximation ran at 19.2uS.
Believe it or not this was still too long. So I implemented it in fixed point and got the sincos down to 2.3uS.
Now that's a spicy meatball!
#56
Posted 26 January 2009 - 10:58 AM
#57
Posted 26 January 2009 - 11:47 AM
#58
Posted 27 January 2009 - 01:34 PM
evarobotics said:
I'm running on a Luminary Micro at 50MHz. The gcc sincos (presumably taylor series) ran in 104uS. Your polynomial approximation ran at 19.2uS.
Believe it or not this was still too long. So I implemented it in fixed point and got the sincos down to 2.3uS.
Sol_HSA said:
v71 said:
#59
Posted 27 January 2009 - 04:02 PM
Nick said:
Posting it in the book would make it accessible to a larger amount of people, and the GPG books are filled with nuggets like these, so it would definitely fit in. And would look nice in your CV. =)
#60
Posted 29 January 2009 - 04:04 PM
Groove said:
I did it for my math library(http://glm.g-truc.net) and they are quiet efficient but low precision. My functions are build to use an "half precision".
I also tryed with the log function but the result was good, VC7.1 is really fastest.
It's also work well with asin, acos, atan and tan functions:
I have try with SSE instructions and I didn't kown this "optimisation" so I very interested :p
I've used Nick's Sin, Cosine stuff for an Iphone project that I am working on... those functions work a treat. Thanks Nick.
The reason I've resurrected this thread is that I need a fast way to compute the ACOS function. The one in the quotes is impractical on an ARM cpu with a VFP. All those multiplications will stall the VFP baddly, so realizing that there are far better people at working out math than me, is there a nice cheap fast way to do this that will give reasonably results.
Thanks for any help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












