On Sat, Feb 13, 2016 at 9:31 AM, Charles R Harris <charlesr.har...@gmail.com > wrote:
> Hi All, > > I'm curious as to what folks think about some choices in the compution of > the remainder function. As an example where different choices can be made > > In [2]: -1e-64 % 1. > Out[2]: 1.0 > > In [3]: float64(-1e-64) % 1. > Out[3]: 0.99999999999999989 > > The first is Python, the second is in my branch. The first is more accurate > numerically, but the modulus is of the same magnitude as the divisor. The > second maintains the convention that the result must have smaller > magnitude than the divisor. There are other corner cases along the same > lines. So the question is, which is more desirable: maintaining numerical > accuracy or enforcing mathematical convention? The differences are on the > order of an ulp, but there will be a skew in the distribution of the > errors if convention is maintained. > > The Fortran modulo function, which is the same basic function as in my > branch, does not specify any bounds on the result for floating numbers, but > gives only the formula, modulus(a, b) = a - b*floor(a/b), which has the > advantage of being simple and well defined ;) > Note that the other enforced bound is that the result have the same sign as the divisor. Python enforces that by adjusting the integer part, I enforce it by adjusting the remainder. Chuck
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org https://mail.scipy.org/mailman/listinfo/numpy-discussion