On Mon, Jun 11, 2018 at 1:00 AM, Ronald Oussoren <ronaldousso...@mac.com>
wrote:

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


EXACTLY!

In [*49*]: math.sin(math.pi)

Out[*49*]: 1.2246467991473532e-16

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

Out[*27*]: 0.9999999999999999

But:

In [*28*]: 1.0 - x

Out[*28*]: 1.1102230246251565e-16

i.e.  x is  within one decimal unit in the last place stored by a float to
1.0.

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
per se)

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)

Out[*46*]: 1.2246467991473532e-16


In [*47*]: round(math.sin(math.pi), 15)

Out[*47*]: 0.0

But anyway:

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:

math.sin(math.degree(something))

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

-CHB


-- 

Christopher Barker, Ph.D.
Oceanographer

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.bar...@noaa.gov
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to