<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 19, 2018 at 8:27 AM, Matthew Brett <span dir="ltr"><<a href="mailto:matthew.brett@gmail.com" target="_blank">matthew.brett@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
On Fri, Jan 19, 2018 at 3:24 PM, Charles R Harris<br>
<div><div class="gmail-h5"><<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br>
><br>
><br>
> On Fri, Jan 19, 2018 at 7:48 AM, Matthew Brett <<a href="mailto:matthew.brett@gmail.com">matthew.brett@gmail.com</a>><br>
> wrote:<br>
>><br>
>> Hi Chuck,<br>
>><br>
>> Thanks for the replies, they are very helpful.<br>
>><br>
>> On Fri, Jan 19, 2018 at 1:51 PM, Charles R Harris<br>
>> <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br>
>> ><br>
>> ><br>
>> > On Fri, Jan 19, 2018 at 6:41 AM, Charles R Harris<br>
>> > <<a href="mailto:charlesr.harris@gmail.com">charlesr.harris@gmail.com</a>> wrote:<br>
>> >><br>
>> >><br>
>> >><br>
>> >> On Fri, Jan 19, 2018 at 3:30 AM, Matthew Brett<br>
>> >> <<a href="mailto:matthew.brett@gmail.com">matthew.brett@gmail.com</a>><br>
>> >> wrote:<br>
>> >>><br>
>> >>> Hi,<br>
>> >>><br>
>> >>> Sorry for my confusion, but I noticed (as a result of the discussion<br>
>> >>> here [1]) that np.rint and the fallback C function [2] seem to round<br>
>> >>> to even.  But - my impression was that C rint, by default, rounds down<br>
>> >>> [3].   Is numpy rint not behaving the same way as the GNU C library<br>
>> >>> rint?<br>
>> >>><br>
>> >>> In [4]: np.rint(np.arange(0.5, 11))<br>
>> >>> Out[4]: array([ 0.,  2.,  2.,  4.,  4.,  6.,  6.,  8.,  8., 10., 10.])<br>
>> >>><br>
>> >>> In [5]: np.round(np.arange(0.5, 11))<br>
>> >>> Out[5]: array([ 0.,  2.,  2.,  4.,  4.,  6.,  6.,  8.,  8., 10., 10.])<br>
>> >><br>
>> >><br>
>> >> The GNU C documentation says that rint "round(s) x to an integer value<br>
>> >> according to the current rounding mode." The rounding mode is<br>
>> >> determined by<br>
>> >> settings in the FPU control word. Numpy runs with it set to round to<br>
>> >> even,<br>
>> >> although, IIRC, there is a bug on windows where the library is not<br>
>> >> setting<br>
>> >> those  bits correctly.<br>
>> ><br>
>> ><br>
>> > Round to even is also the Python default rounding mode.<br>
>><br>
>> Do you mean that it is Python setting the FPU control word?  Or do we<br>
>> set it?  Do you happen to know where that is in the source?  I did a<br>
>> quick grep just now without anything obvious.<br>
><br>
><br>
> I can't find official (PEP) documentation, but googling indicates that in<br>
> Python 3, `round` rounds to even, and in Python 2 it rounds up. See also<br>
> <a href="https://docs.python.org/3/whatsnew/3.0.html" rel="noreferrer" target="_blank">https://docs.python.org/3/<wbr>whatsnew/3.0.html</a>.<br>
<br>
</div></div>But I guess this could be the Python implementation of round, rather<br>
than rint and the FPU control word?  I'm asking because the question<br>
arose about npy_rint at the C level ...<br></blockquote><div><br></div><div>I'm pretty sure Python sets the FPU control word. Note that Python itself doesn't have a public interface for setting it, nor does Java. The GNU library documentation has the following:</div><div><br></div><dt style="color:rgb(0,0,0);font-family:"Times New Roman"">Round to nearest.</dt><div><span style="color:rgb(0,0,0);font-family:"Times New Roman"">This is the default mode. It should be used unless there is a specific need for one of the others. In this mode results are rounded to the nearest representable value. If the result is midway between two representable values, the even representable is chosen.</span><span style="color:rgb(0,0,0);font-family:"Times New Roman""> </span><em style="color:rgb(0,0,0);font-family:"Times New Roman"">Even</em><span style="color:rgb(0,0,0);font-family:"Times New Roman""> </span><span style="color:rgb(0,0,0);font-family:"Times New Roman"">here means the lowest-order bit is zero. This rounding mode prevents statistical bias and guarantees numeric stability: round-off errors in a lengthy calculation will remain smaller than half of</span><span style="color:rgb(0,0,0);font-family:"Times New Roman""> </span><code style="color:rgb(0,0,0)">FLT_EPSILON</code><span style="color:rgb(0,0,0);font-family:"Times New Roman"">.</span> </div><div><br></div><div>Chuck</div></div></div></div>