delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/02/28/08:19:07

Message-Id: <3.0.6.32.19990228081852.008acda0@pop.globalserve.net>
X-Sender: derbyshire AT pop DOT globalserve DOT net
X-Mailer: QUALCOMM Windows Eudora Light Version 3.0.6 (32)
Date: Sun, 28 Feb 1999 08:18:52 -0500
To: djgpp AT delorie DOT com
From: Paul Derbyshire <pderbysh AT usa DOT net>
Subject: Re: sin, cos ??
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

At 02:19 PM 2/28/99 +0200, you wrote:
>> const long double pi = 3.141592653589793
>
>Don't ``invent'' Pi, use the constant M_PI.

1. M_PI is a macro. 'Nuff said.
2. That value is accurate to the last decimal place, anyways.

>> template <class F> // 'F' as in 'Floating point'
>> inline F deg2rad (F deg) { return deg*pi/180.0; }
>
>You don't need to go to C++ just to have inline functions.

Not using gcc, but this does provide a deg2rad that works with floats,
doubles, and long doubles without any conversions being done.

>The macros Nate suggested don't have any side effects.

Well, those specific ones don't, as it just so happens, as long as you
don't pass something pathological as argument, but macros on the whole are
best avoided. C++ makes this easy with the consts, templates, and inlines.

-- 
   .*.  "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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019