[Python-ideas] Fwd: Trigonometry in degrees
Robert Vanden Eynde
robertve92 at gmail.com
Wed Jun 13 06:00:09 EDT 2018
What was wrong with my initial implementation with a lookup table ? :D
if x % 90 == 0:
return (0, 1, 0, -1)[int(x // 90) % 4]
If you want to support multiples of 30, you can do % 30 and // 30.
Le mer. 13 juin 2018 à 09:51, Stephan Houben <stephanh42 at gmail.com> a
> Op di 12 jun. 2018 12:41 schreef Nathaniel Smith <njs at pobox.com>:
>> On Tue, Jun 12, 2018, 00:03 Stephan Houben <stephanh42 at gmail.com> wrote:
>>> Hi all,
>>> 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
>>> nearest for
>> You observed this on your system, but math.sin uses the platform libm,
>> which might do different things on other people's systems.
> Ok, I updated the code to treat all the values 0, 30, 45, 60 and 90
>>> 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.
>> Again, monotonicity is preserved on your system, but it might not be on
>> others. It's not clear that this matters, but then it's not clear that any
>> of this matters...
> 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