Velocity Reviews > C's trig functions

C's trig functions

John Smith
Guest
Posts: n/a

 04-25-2005
I just broke up with my girlfriend, so, to sublimate my sexual tensions,

http://forensics.calcinfo.com/

This guy has developed a method that he uses to determine chip lineage
in old calculators (he needs a girlfriend too). Various chips will
produce various results when you make this calculation:

n = sin(cos(tan(atan(acos(asin(9.0)))))) in degrees.

With the Windows calculator I get the following results starting with
sin(9.0)in degree mode:

0.156434465040230869010105319467167
0.99999627274288502411751620501135
0.0174549998554886607913941409283485
0.99999627274288502411751620501135
0.156434465040230869010105319467167
9.00000000000000000000000000000003

I decided to try it with C's trig functions:

#include <stdio.h>
#include <math.h>
#define PI 3.14159265358979323846

int main(void)
{
long double n;

printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
/* final n = sin(cos(tan(atan(acos(asin(9.0)))))) */

return 0;
}

The program produces this output:

0.15643446504023086901
0.99999627274288502409
0.01745499985548866218
0.00030464720898864997
1.57079100969804273100
0.02741891042497898145

The first three values are OK, but when the inverse functions are
invoked it goes off the tracks. What's wrong?

Gregory Pietsch
Guest
Posts: n/a

 04-25-2005
Here's a quick check: Wouldn't the last three calls (atan, acos, asin)
the way you have them?

Happy debugging, Gregory Pietsch

Peter Nilsson
Guest
Posts: n/a

 04-25-2005
John Smith wrote:
>
> http://forensics.calcinfo.com/
>
> With the Windows calculator I get the following results starting with

> sin(9.0)in degree mode:
>
> 0.156434465040230869010105319467167
> 0.99999627274288502411751620501135
> 0.0174549998554886607913941409283485
> 0.99999627274288502411751620501135
> 0.156434465040230869010105319467167
> 9.00000000000000000000000000000003
>
> I decided to try it with C's trig functions:
>
> #include <stdio.h>
> #include <math.h>
> #define PI 3.14159265358979323846
>
> int main(void)
> {
> long double n;
>
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);

Fine, to here.

> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);

Try...

printf("%.20Lf\n", n);
printf("%.20Lf\n", n);
printf("%.20Lf\n", n);

> /* final n = sin(cos(tan(atan(acos(asin(9.0)))))) */
>
> return 0;
> }

--
Peter

Keith Thompson
Guest
Posts: n/a

 04-26-2005
John Smith <(E-Mail Removed)> writes:
> I just broke up with my girlfriend, so, to sublimate my sexual
> tensions, I began reading this:
>
> http://forensics.calcinfo.com/
>
> This guy has developed a method that he uses to determine chip lineage
> in old calculators (he needs a girlfriend too). Various chips will
> produce various results when you make this calculation:
>
> n = sin(cos(tan(atan(acos(asin(9.0)))))) in degrees.

What do you expect asin(9.0) to do? asin() expects an argument in the
range -1.0 to +1.0, and returns an angle (normally in radians); it
fails if its argument is outside that range. Converting asin()'s
argument from degrees to radians makes no mathematical sense; if you
want to work in degrees, you need to convert the *result* from radians
to degrees.

> With the Windows calculator I get the following results starting with
> sin(9.0)in degree mode:

[...]

Starting with sin(9.0) is inconsistent with the expression above. I
suspect what you mean is:

n = asin(acos(atan(tan(cos(sin(9.0))))))

(where 9.0 is in degrees).

As you know, unlike most interactive calculators, C's trig functions
have no "degree mode", which is why you need to do the conversions
manually. The C equivalent of sin(x), where x is expressed in
degrees, would be sin(DEG2RAD(x)). The C equivalent of asin(x), where
the result is to be expressed in degrees, would be RAD2DEG(asin(x)).

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Martin Ambuhl
Guest
Posts: n/a

 04-26-2005
John Smith wrote the demented claim that:
> #define PI 3.14159265358979323846
>
> int main(void)
> {
> long double n;
>
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> printf("%.20Lf\n", n);
> /* final n = sin(cos(tan(atan(acos(asin(9.0)))))) */

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Do you really thing that
asin(acos(atan(tan(cos(sin(x)))))
is the same operationally as
sin(cos(tan(atan(acos(asin(x)))))?

Thomas
Guest
Posts: n/a

 04-26-2005
??,
"Keith Thompson" <(E-Mail Removed)> ???? news:(E-Mail Removed)...
> John Smith <(E-Mail Removed)> writes:
> > I just broke up with my girlfriend, so, to sublimate my sexual
> > tensions, I began reading this:
> >
> > http://forensics.calcinfo.com/
> >
> > This guy has developed a method that he uses to determine chip lineage
> > in old calculators (he needs a girlfriend too). Various chips will
> > produce various results when you make this calculation:
> >
> > n = sin(cos(tan(atan(acos(asin(9.0)))))) in degrees.

>
> What do you expect asin(9.0) to do? asin() expects an argument in the
> range -1.0 to +1.0, and returns an angle (normally in radians); it
> fails if its argument is outside that range. Converting asin()'s
> argument from degrees to radians makes no mathematical sense; if you
> want to work in degrees, you need to convert the *result* from radians
> to degrees.
>
> > With the Windows calculator I get the following results starting with
> > sin(9.0)in degree mode:

> [...]
>
> Starting with sin(9.0) is inconsistent with the expression above. I
> suspect what you mean is:
>
> n = asin(acos(atan(tan(cos(sin(9.0))))))
>
> (where 9.0 is in degrees).
>
> As you know, unlike most interactive calculators, C's trig functions
> have no "degree mode", which is why you need to do the conversions
> manually. The C equivalent of sin(x), where x is expressed in
> degrees, would be sin(DEG2RAD(x)). The C equivalent of asin(x), where
> the result is to be expressed in degrees, would be RAD2DEG(asin(x)).
>
> --
> Keith Thompson (The_Other_Keith) (E-Mail Removed)

<http://www.ghoti.net/~kst>
> San Diego Supercomputer Center <*>

<http://users.sdsc.edu/~kst>
> We must do something. This is something. Therefore, we must do this.

Keith Thompson
Guest
Posts: n/a

 04-26-2005
"Thomas" <(E-Mail Removed)> writes:
> ??,
> "Keith Thompson" <(E-Mail Removed)> ???? news:(E-Mail Removed)...

[snip]

You wrote two question marks and then quoted my entire article.

Did you have a question?

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

John Smith
Guest
Posts: n/a

 04-26-2005
Keith Thompson wrote:

> Starting with sin(9.0) is inconsistent with the expression above. I
> suspect what you mean is:
>
> n = asin(acos(atan(tan(cos(sin(9.0))))))

About two minutes after I posted this, I realized I had written it
backwards.
>
> (where 9.0 is in degrees).
>
> As you know, unlike most interactive calculators, C's trig functions
> have no "degree mode", which is why you need to do the conversions
> manually. The C equivalent of sin(x), where x is expressed in
> degrees, would be sin(DEG2RAD(x)). The C equivalent of asin(x), where
> the result is to be expressed in degrees, would be RAD2DEG(asin(x)).
>

I hate to look stupid, but thanks to you and others who pointed out my
mistakes.

JS