<div dir="ltr">2018-06-13 12:08 GMT+02:00 Robert Vanden Eynde <span dir="ltr"><<a href="mailto:robertve92@gmail.com" target="_blank">robertve92@gmail.com</a>></span>:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>Then of you also want 45, you could do % 15 ? :D</div></div></blockquote><div><br></div><div>Sure, but how the lookup is done in the Python reference code is</div><div>ultimately not so important, since it will need to be rewritten in C</div><div>if it is to be included in the math package (math is C-only).</div><div><br></div><div>And then we'll probably end up with a bunch of if-checks against</div><div>the common values.</div><div><br></div><div>Stephan<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div><div class="h5"><br><br><div class="gmail_quote"><div dir="ltr">Le mer. 13 juin 2018 à 12:07, Stephan Houben <<a href="mailto:stephanh42@gmail.com" target="_blank">stephanh42@gmail.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">2018-06-13 12:00 GMT+02:00 Robert Vanden Eynde <span dir="ltr"><<a href="mailto:robertve92@gmail.com" rel="noreferrer" target="_blank">robertve92@gmail.com</a>></span>:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">What was wrong with my initial implementation with a lookup table ? :D<div dir="auto"><br></div><div dir="auto"><span><div dir="auto">def sind(x):</div><div dir="auto">    if x % 90 == 0:</div><div dir="auto">        return (0, 1, 0, -1)[int(x // 90) % 4]</div><div dir="auto">    else:</div><div dir="auto">        return sin(radians(x))</div></span></div></div></blockquote><div><br></div><div>I kinda missed it, but now you ask:</div><div><br></div><div>1. It's better to reduce the angle while still in degrees since one of the advantages<br></div><div>   of degrees is that the reduction can be done exactly. Converting very large angles</div><div>   first to radians and then taking the sine can introduce a large error,</div><div><br></div><div>2. I used fmod instead of % on advice in this thread.</div><div><br></div><div>3. I also wanted to special case, 30, 45, and 60.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><span><div dir="auto"><br></div></span><div dir="auto">If you want to support multiples of 30, you can do % 30 and // 30.</div></div></div></blockquote><div><br></div><div>Sure, but I also wanted to special-case 45.</div><div><br></div><div>Stephan<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div class="gmail_quote"><div><div class="m_-9102009970034318570m_4003774927205875920h5"><div dir="ltr">Le mer. 13 juin 2018 à 09:51, Stephan Houben <<a href="mailto:stephanh42@gmail.com" rel="noreferrer" target="_blank">stephanh42@gmail.com</a>> a écrit :<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_-9102009970034318570m_4003774927205875920h5"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr">Op di 12 jun. 2018 12:41 schreef Nathaniel Smith <<a href="mailto:njs@pobox.com" rel="noreferrer noreferrer noreferrer" target="_blank">njs@pobox.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div class="gmail_quote"><div dir="ltr">On Tue, Jun 12, 2018, 00:03 Stephan Houben <<a href="mailto:stephanh42@gmail.com" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">stephanh42@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi all,</div><div><br></div><div>I wrote a possible implementation of sindg:<br></div><div><br></div><div><a href="https://gist.github.com/stephanh42/336d54a53b31104b97e46156c7deacdd" rel="noreferrer noreferrer noreferrer noreferrer noreferrer" target="_blank">https://gist.github.com/<wbr>stephanh42/<wbr>336d54a53b31104b97e46156c7deac<wbr>dd</a></div><div><br></div><div>This code first reduces the angle to the [0,90] interval.</div><div>After doing so, it can be observed that the simple implementation</div><div>  math.sin(math.radians(angle))</div><div>produces exact results for 0 and 90, and a result already rounded to nearest for</div><div>60.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">You observed this on your system, but math.sin uses the platform libm, which might do different things on other people's systems.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto">Ok, I updated the code to treat all the values 0, 30, 45, 60 and 90 specially.</div><div dir="auto"><br></div><div dir="auto">Stephan</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><br></div><div>For 30 and 45, this simple implementation is one ulp too low.</div><div>So I special-case those to return the correct/correctly-rounded value instead.</div><div>Note that this does not affect monotonicity around those values.</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">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...</div><div dir="auto"><br></div><div dir="auto">-n</div></div>
</blockquote></div></div></div></div></div>
______________________________<wbr>_________________<span><br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" rel="noreferrer noreferrer" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</span></blockquote></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" rel="noreferrer" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
<br></blockquote></div><br></div></div>