<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Jun 10, 2018 at 10:48 PM, Steven D'Aprano <span dir="ltr"><<a href="mailto:steve@pearwood.info" target="_blank">steve@pearwood.info</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
> In regard to the "special values", and exact results -- a good math lib<br>
> should return results that are "exact" in all but maybe the last digit<br>
> stored. So you could check inputs and outputs with, e.g. math.isclose() to<br>
> give people the "exact" results. -- and keep it all in floating point.<br>
<br>
</span>I wish Uncle Timmy or Mark Dickinson were around to give a definite <br>
answer, but in their absence I'll have a go. I'm reasonably sure <br>
that's wrong.<br></blockquote><div><br></div><div>hmm -- I'm no numerical analyst, but I could have sworn I learned (from Kahan himself) that the trig functions could (and were, at least in the HP calculators :-) ) be computed to one digit of accuracy. He even proved how many digits of pi you'd have to store to do that (though I can't say I understood the proof) -- I think you needed all those digits of pi because the trig functions are defined on the range 0 -- pi/2, and any larger value needs to be mapped to that domain -- if someone asks for the sin(e100), you need to know pretty exactly what x % pi/4 is. </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The problem with trig functions is that they suffer from "the <br>
table maker's dilemma", so it is very hard to guarantee a correctly <br>
rounded result without going to ludicrous extremes:<br>
<br>
<a href="http://perso.ens-lyon.fr/jean-michel.muller/Intro-to-TMD.htm" rel="noreferrer" target="_blank">http://perso.ens-lyon.fr/jean-<wbr>michel.muller/Intro-to-TMD.htm</a><br>
<br>
So I think that there's no guarantee given for trancendental functions <br>
like sine, cosine etc.<br></blockquote><div><br></div><div>so -- if that's the case, I still think we know that while the last digit may not be the best rounded value to the real one, the second to last digit is correct. And if not, then there's nothing we could do other than implement the math lib :-)</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
But even if they were, using isclose() is the wrong solution. Suppose <br>
sin(x) returns some number y, such that isclose(y, 0.0) say. You have no <br>
way of knowing that y is an inaccurate result that ought to be zero, or <br>
whether the answer should be non-zero and y is correct. You cannot <br>
assume that "y is close to zero, therefore it ought to be zero".<br></blockquote><div><br></div><div>no, but you can say "y is as close to zero as I care about" we are already restricted to not knowing the distinction within less than an eps -- so making the "effective eps" a bit larger would result in more esthetically pleasing results.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
It's not just zero, the same applies for any value. That's just moving <br>
rounding errors from one input to a slightly different input.<br>
<br>
# current situation<br>
sine of x returns y, but the mathematical exact result is exactly z<br>
<br>
# suggested "fix"<br>
sine of x ± a tiny bit returns exactly z, but ought to return y<br>
<br>
Guessing what sin or cos "ought to" return based on either the inexact <br>
input or inexact output is not a good approach.<br></blockquote><div><br></div><div>I don't think that's what it would be -- rather, it would be returning a bit less precision in exchange for more esthetically pleasing results :-)</div><div><br></div><div>Note that there is no way I would advocate using this for the stdlib trig functions -- only for a purpose library.</div><div><br></div><div>I'm also suggesting that it would result in equally good results to what is being proposed: using integer degrees, or a pi or tau based units. </div><div><br></div><div>If you used integer degrees, then you'd have exactly, say pi (180 degrees), but a precision of only pi/180 -- much less than the 15 digits or so you'd get if you rounded the regular floating point results.</div><div><br></div><div>And if you used tau based units, you'd be back to the same thing -- 0.5 tau could be exact, but what would you do for a bit bigger or smaller than that? use FP :-)</div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We can only operate on multiples of pi, <br>
which is *close to* but not the same as π. That's why it is okay that <br>
tan(pi/2) returns a huge number instead of infinity or NAN. That's <br>
because the input is every so slightly smaller than π/2. That's exactly <br>
the behavior you want when x is ever so slightly smaller than π/2.<br></blockquote><div><br></div><div>I suppose so, but is there a guarantee that the FP representation of <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">π/2 is a tiny bit less than the exact value, rather than a tiny bit more? which would result in VERY different answers:</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">




<span></span>





<p class="m_-6721184241488440602gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_-6721184241488440602gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>10</b></span><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">math.tan(math.pi / </span><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">2.0</span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="m_-6721184241488440602gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="m_-6721184241488440602gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-6721184241488440602gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>10</b></span><span class="m_-6721184241488440602gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">1.633123935319537e+16</span></p>
<p class="m_-6721184241488440602gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);min-height:13px"><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="m_-6721184241488440602gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">In [</span><span class="m_-6721184241488440602gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>11</b></span><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">]: </span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">math.tan(math.pi / </span><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">2.0</span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures"> + </span><span class="m_-6721184241488440602gmail-s1" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">2e-16</span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="m_-6721184241488440602gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0)"><span class="m_-6721184241488440602gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">Out[</span><span class="m_-6721184241488440602gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(255,59,30)"><b>11</b></span><span class="m_-6721184241488440602gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(178,54,34)">]: </span><span class="m_-6721184241488440602gmail-s3" style="font-variant-ligatures:no-common-ligatures">-6218431163823738.0</span></p>


<br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">(though equally "correct")</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Also -- 1.6 e+</span>16 is actually pretty darn small compared to FP range.</div><div><br></div><div>So a library that wants to produce "expected" results may want to do something with that -- something like:</div><div><br></div><div>




<span></span>





<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>119</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>def</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s4" style="font-variant-ligatures:no-common-ligatures;color:rgb(60,159,242)">pretty_tan</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(x):</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">    </span>tol = </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">3e-16</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>diff = x % (pi / </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">)</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>if</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">abs</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">(diff) < tol:</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">        </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>return</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">float</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">"-Inf"</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">) <span class="gmail-Apple-converted-space">         </span></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>elif</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> (pi /</span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">2</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">) - diff < tol:</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"><span class="gmail-Apple-converted-space">        </span></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><b>return</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">float</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span class="gmail-s6" style="font-variant-ligatures:no-common-ligatures;color:rgb(205,121,35)">"Inf"</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">)</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>return</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> math.tan(x)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">     </span>...:<span class="gmail-Apple-converted-space"> </span></span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">     </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>120</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: </span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">x = pi / </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">2</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> - </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">5e-16</span></p>
<p class="gmail-p3" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255);min-height:13px"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">In [</span><span class="gmail-s2" style="font-variant-ligatures:no-common-ligatures;color:rgb(46,231,33)"><b>121</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">]: <b>for</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> i </span><span class="gmail-s7" style="font-variant-ligatures:no-common-ligatures;color:rgb(208,59,255)"><b>in</b></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">range</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">(</span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">10</span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)">):</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span>val = x + i * </span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)">1e-16</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><span class="gmail-Apple-converted-space">     </span>...: </span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">    </span></span><span class="gmail-s5" style="font-variant-ligatures:no-common-ligatures;color:rgb(52,163,39)"><b>print</b></span><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"> val, pretty_tan(val)</span></p>
<p class="gmail-p1" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,163,39);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">     </span>...:<span class="gmail-Apple-converted-space"> </span></span><span class="gmail-s3" style="font-variant-ligatures:no-common-ligatures;color:rgb(0,0,0)"> <span class="gmail-Apple-converted-space">   </span></span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 1.9789379661e+15</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 1.9789379661e+15</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -inf</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -2.61194216074e+15</span></p>
<p class="gmail-p2" style="margin:0px;font-variant-numeric:normal;font-variant-east-asian:normal;font-weight:normal;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,0,0);background-color:rgb(255,255,255)"><span class="gmail-s1" style="font-variant-ligatures:no-common-ligatures">1.57079632679 -2.61194216074e+15</span></p>


<br></div>You'd want to tweak that tolerance value to be as small as possible, and do somethign to make it more symmetric, but you get the idea.</div><div class="gmail_quote"><br></div><div class="gmail_quote">The goal is that if you have an input that is about as close as you can get to pi/2, you get inf or -inf as a result.</div><div class="gmail_quote"><br></div><div class="gmail_quote">This does mean you are tossing away a tiny bit of precision -- you could get a "correct" value for those values really close to pi/2, but it would be prettier...</div><div class="gmail_quote"><br></div><div class="gmail_quote">-CHB</div><div class="gmail_quote"><br></div><div class="gmail_quote"><br><div><br></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><br></div><div><br></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="m_-6721184241488440602m_7860771915105479626HOEnZb"><div class="m_-6721184241488440602m_7860771915105479626h5"><br>
<br>
-- <br>
Steve<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/mailma<wbr>n/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/codeofco<wbr>nduct/</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="m_-6721184241488440602m_7860771915105479626gmail_signature" data-smartmail="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>