[Python-ideas] Fwd: Trigonometry in degrees
stephanh42 at gmail.com
Tue Jun 12 03:02:43 EDT 2018
I wrote a possible implementation of sindg:
This code first reduces the angle to the [0,90] interval.
After doing so, it can be observed that the simple implementation
produces exact results for 0 and 90, and a result already rounded to
For 30 and 45, this simple implementation is one ulp too low.
So I special-case those to return the correct/correctly-rounded value
Note that this does not affect monotonicity around those values.
So I am still unsure if this belong in the stdlib, but if so, this is how
it could be done.
2018-06-12 8:50 GMT+02:00 Chris Angelico <rosuav at gmail.com>:
> On Tue, Jun 12, 2018 at 4:40 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> > Tim Peters wrote:
> >> 1. Python's float "%" is unsuitable for argument reduction; e.g.,
> >> >>> -1e-14 % 360.0
> >> 360.0
> >> `math.fmod` is suitable, because it's exact:
> >> >>> math.fmod(-1e-14, 360.0)
> >> -1e-14
> > So why doesn't float % use math.fmod?
> (the latter two being footnotes from the section in the first link)
> With real numbers, divmod (and thus the // and % operators) would
> always return values such that:
> div, mod = divmod(x, y):
> 1) div*y + mod == x
> 2) sign(mod) == sign(y)
> 3) 0 <= abs(mod) < abs(y)
> But with floats, you can't guarantee all three of these. The divmod
> function focuses on the first, guaranteeing the fundamental arithmetic
> equality, but to do so, it sometimes has to bend the third one and
> return mod==y.
> There are times when it's better to sacrifice one than the other, and
> there are other times when it's the other way around. We get the two
> Python-ideas mailing list
> Python-ideas at python.org
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas