[Python-ideas] Fwd: Trigonometry in degrees
chris.barker at noaa.gov
Mon Jun 11 13:05:10 EDT 2018
On Mon, Jun 11, 2018 at 1:00 AM, Ronald Oussoren <ronaldoussoren at mac.com>
> What is the real world advantage of such a class? So far I’ve only seen
> examples where the current behavior is said to be confusing for students.
In [*49*]: math.sin(math.pi)
If the difference between 1.2246467991473532e-16 and zero is important to
you, you've got bigger issues to deal with, and you'd better have a decent
grasp of floating point computation's limitations.
This is not that different than using Decimal, because it is confusing or
aesthetically unpleasing to get something other than 1 (for example) when
you add 0.1 up ten times:
In [*25*]: x = 0.0
In [*26*]: *for* i *in* range(10): x += 0.1
In [*27*]: x
In [*28*]: 1.0 - x
i.e. x is within one decimal unit in the last place stored by a float to
Which is to say -- there is no practical difference within the abilities of
floating point, and Decimal, while it would present this particular result
exactly, isn't any more "accurate" in general (unless you use more
precision, which is a result of variable precision, not decimal arithmetic
So -- If there is a nifty way to specify that I want, say, the sin of
"exactly pi", then the code could special case that, and return exactly
zero. But what if you happen to pass in a value just a tiny bit larger than
pi? then you have a potential discontinuity at pi, because you'd still have
to use the regular FP computation for any non-exact multiple of pi.
All this means that you will get a very similar result by rounding your
outputs to a digit less than full FP precision:
In [*46*]: math.sin(math.pi)
In [*47*]: round(math.sin(math.pi), 15)
There *may* be a nice use-case for a more "friendly" trig package,
particularly in education, but I don't think it would ever belong in the
std lib. (though maybe I'd change my mind if it saw really wide use)
However simiply adding a few names like:
sindeg, cosdeg, etc,
to save folks from having to type:
is a fine idea -- and it may make it a bit more clear, when people go
looking for the "Sine" function, that they don't want to use degrees with
the regular one...
Christopher Barker, Ph.D.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas