[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [avr-gcc-list] error with acos() ?

**From**: |
Jamie Morken |

**Subject**: |
Re: [avr-gcc-list] error with acos() ? |

**Date**: |
Sat, 27 Jul 2002 18:38:59 -0700 |

Hi,
Sorry to reply to my own email :)
I think I may have figured out the problem with acos(x);
acos(x)=atan2(sqrt(1-x^2),x);
the atan2 has the arguments backwards I think.
atan2(x,y) should be atan2(y,x)
acos(x)=2*atan(sqrt((1-x)/(1+x))) x>=0
=pi - 2*atan(sqrt((1+x)/(1-x))) x<0
atan2(y,x)=atan(y/x) x>0
atan2(y,x)=atan(y/x)+pi x<0, y>=0
atan2(y,x)=pi/2 x=0, y>0
atan2(y,x)=atan(y/x)-pi x<0, y<0
atan2(y,x)=-pi/2 x=0, y<0
atan2(0,0) is undefined and should give an error.
Maybe the checking of x to 0 is mixed up somehow?
cheers,
Jamie Morken
>* Hi,*
>* *
>* I am using acos() and think there is an error with it.*
>* *
>* Here is the line I use:*
>* *
>* temp4 = acos(0.999911);*
>* *
>* This should return 0.013316 I think,*
>* but it returns 0.0878546*
>* *
>* I am using avr-gcc 3.2*
>* *
>* cheers,*
>* Jamie Morken*
>* *
>* *
>* *
>* avr-gcc-list at http://avr1.org*
avr-gcc-list at http://avr1.org