Mail Archives: djgpp/1999/02/27/02:15:34
At 12:19 PM 2/25/99 -0800, you wrote:
>Paradox wrote:
>>
>> Is there another function that uses degrees?
>
>No, but you can easily convert between the two.
>
>#include <math.h>
>#define DEG2RAD(deg) ((deg)*(M_PI/180.0))
>#define RAD2DEG(rad) ((rad)*(180.0/M_PI))
Ack! Macros!
const long double pi = 3.141592653589793
template <class F> // 'F' as in 'Floating point'
inline F deg2rad (F deg) { return deg*pi/180.0; }
template <class F>
inline F rad2deg (F rad) { return 180.0*rad/pi; }
There. Nice and type-safe and free of bogons with arguments that have side
effects. More readable too, just as inlined and quick, and moreover, if you
have egcs you can stick these in your own namespace and keep them from
cluttering the global one.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot |http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh AT usa DOT net
Programmer & Humanist|ICQ: 10423848|
- Raw text -