Math/Trig functions

It’s hard to believe that after almost 15 years of QNX programming I’m
working on my first heavy math program. I need to do a lot of trig. I
notices that pi isn’t directly defined anywhere and that all of the trig
functions take their arguments in radians and not degrees. I also don’t see
any functions for converting degrees to radian and visaversa. Am I missing
something? Do these things exist anywhere that I don’t see?

So, I am using:

const double pi = asin( 1.0 ) * 2.0;
double deg2rad( double deg ) { return deg * pi / 180.0; }
double rad2deg( double rad ) { return rad * 180 / pi; }

Then I defined a bunch of functions like:

double Sin ( double deg ) { return sin( deg2rad( deg ) ); }

Does anyone see any problems with this technique?

I really can’t believe that there isn’t a more ANSI standard way of doing
this.

This looks fine to me Bill. If you are really picky you might want to
check and see how close asin(1.0) comes to Pi. You also might want
to use #define’s to reduce overhead slightly. I recall that Pi was
usually defined in math.h, but it doesn’t seem to be part of Watcom’s
implementation.


Previously, Bill Caroselli (Q-TPS) wrote in qdn.public.qnx4.devtools:

It’s hard to believe that after almost 15 years of QNX programming I’m
working on my first heavy math program. I need to do a lot of trig. I
notices that pi isn’t directly defined anywhere and that all of the trig
functions take their arguments in radians and not degrees. I also don’t see
any functions for converting degrees to radian and visaversa. Am I missing
something? Do these things exist anywhere that I don’t see?

So, I am using:

const double pi = asin( 1.0 ) * 2.0;
double deg2rad( double deg ) { return deg * pi / 180.0; }
double rad2deg( double rad ) { return rad * 180 / pi; }

Then I defined a bunch of functions like:

double Sin ( double deg ) { return sin( deg2rad( deg ) ); }

Does anyone see any problems with this technique?

I really can’t believe that there isn’t a more ANSI standard way of doing
this.

\


Mitchell Schoenbrun --------- maschoen@pobox.com

I would have expected it to be in math.h too, or limits.h or something.h.

“Mitchell Schoenbrun” <maschoen@pobox.com> wrote in message
news:Voyager.020720163552.18843B@schoenbrun.com

This looks fine to me Bill. If you are really picky you might want to
check and see how close asin(1.0) comes to Pi. You also might want
to use #define’s to reduce overhead slightly. I recall that Pi was
usually defined in math.h, but it doesn’t seem to be part of Watcom’s
implementation.


Previously, Bill Caroselli (Q-TPS) wrote in qdn.public.qnx4.devtools:
It’s hard to believe that after almost 15 years of QNX programming I’m
working on my first heavy math program. I need to do a lot of trig. I
notices that pi isn’t directly defined anywhere and that all of the trig
functions take their arguments in radians and not degrees. I also don’t
see
any functions for converting degrees to radian and visaversa. Am I
missing
something? Do these things exist anywhere that I don’t see?

So, I am using:

const double pi = asin( 1.0 ) * 2.0;
double deg2rad( double deg ) { return deg * pi / 180.0; }
double rad2deg( double rad ) { return rad * 180 / pi; }

Then I defined a bunch of functions like:

double Sin ( double deg ) { return sin( deg2rad( deg ) ); }

Does anyone see any problems with this technique?

I really can’t believe that there isn’t a more ANSI standard way of
doing
this.




\

Mitchell Schoenbrun --------- > maschoen@pobox.com