Boost logo

Boost :

From: Walter Landry (wlandry_at_[hidden])
Date: 2003-12-10 22:14:09


Matthias Schabel <boost_at_[hidden]> wrote:
> > You want to redefine the trig functions to only take SI<double>::Angle
> > units? The trig functions don't take things with units, they take
> > numbers. It is completely reasonable and common to take sin(A/B),
> > where A and B both have the same units. You would require people to
> > write sin(radians *A/B), which is just wrong.
>
> I'm proposing no such thing; the new overloaded trig functions I
> defined will match dimensioned quantities representing any angle
> type in any unit model you desire, automatically convert to radians
> if necessary, and compute the desired value. They have no impact
> whatsoever on users who prefer to call the standard cmath functions.
> Furthermore, I can't see anything _wrong_ with allowing people to
> write sin(_radians*A/B) or sin(_degrees*A/B) or, for that matter,
> sin(_my_funky_angular_unit_type*A/B). It's a way of making the
> intent transparent and guarantee correctness by having the compiler
> do the conversion. It's a common source of errors, especially for
> beginning programmers and people who don't have much familiarity
> with trig, to try using degrees as the argument to std::sin and to
> be unpleasantly surprised with a runtime problem. Explicitly
> specifying the unit of angular measure allows the compiler to catch
> these otherwise nasty bugs...

I guess my main thesis is that an angle is not just something that you
feed into a trig function. It is common to manipulate angles as just
the numbers they are. If you want to provide an implementation of the
trig library that accepts degrees and gradians, that's fine with me.
But don't make radians into a "unit".

> > You don't normally put degrees or gradians into a Taylor series. You
> > do that all the time with radians. It is true that you can convert a
> > degree to a radian, but you can also convert a centimeter to a second
> > using the rather common conversion factor of the speed of light.
>
> Radians happen to be the "natural" unit for measuring angular
> quantities in that there are defined to be precisely 2 pi radians in
> a unit circle so that the ratio of radians in a full circle to the
> circumference of that circle is exactly one as opposed to 360/(2 pi)
> as it is for degrees.

Radians are the ratio of one length to another. Degrees are a unit
that can be converted to a raw number by multiplying by pi/180. Much
like you can convert a speed into a raw number by dividing by the
speed of light or the speed of sound.

> As far as Taylor series go, it may not be "normal", but there's no
> problem doing a Taylor series expansion of the function sin with a
> degree argument :
>
> sin(x -> radians) = x - x^3/3! + x^5/5! - ...
>
> sin(x -> degrees) = sin(2 pi x/360)
> = (2 pi/360) x - (2 pi/360)^3 x^3/3! +
> (2 pi/360)^5 x^5/5! - ...

You're just converting the units in the expression. You can do that
for any units. The benefit of raw numbers is that you don't have to
convert.

> The natural units analogy is specious - degrees and radians are
> different ways of measuring the same quantity, which is an abstract
> mathematical entity, irrespective of other assumptions. Natural
> units take advantage of the fact that fundamental physical constants
> exist. In a parallel universe with different values of c, hbar,
> etc... lengths expressed in natural units would differ while angles
> would not.

Degrees are a historic way of measuring angles, much like fahrenheit
and centigrade are historic ways of measuring temperature. To do
actual work, you have to convert them to the appropriate form. For
degrees, the appropriate form is a pure number. For temperature, that
would be kelvins (or ergs).

Regards,
Walter Landry
wlandry_at_[hidden]


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk