BUG: improve log2 windows compiler fallback of log2

Fallback (similar to python3.4 math.log2) provides int(log(2**i)) == i
in default rounding mode.
Non-default rounding modes not tested but if it does not work we are at
least not worse than python.
Closes gh-4787
Not sure I follow -- for all i in range(1, 65, 2.**i and log2(2.**i) are
both exactly representable in IEEE754 double or single precision. So a
correctly rounded log2 will return the exact answer regardless of rounding
mode, and any reasonable implementation of int() will surely pass through
exact integers unscathed. Or am I missing something...?

On Sat, Jun 7, 2014 at 5:33 PM, Julian Taylor <notifications@github.com>
wrote:

> In numpy/core/tests/test_umath.py:
>
> > @@ -189,6 +190,27 @@ def test_log2_values(self) :
> >              yf = np.array(y, dtype=dt)
> >              assert_almost_equal(np.log2(xf), yf)
> >
> > +    def test_log2_ints(self):
> > +        # a good log2 implementation should provide this,
> > +        # might fail on OS with bad libm
> > +        for i in range(1, 65):
> > +            v = np.log2(2.**i)
> > +            assert_equal(int(v), i)
>
> we don't really want to assure v has an integer value as that is not
> generally the case.
> what we want here is check when the return value of log2 is cast to an
> integer it will be the expected integer as that is what e.g. indexing does.
> at least in round-to-nearest mode this is true for a good log2
> implementation with 0.5 ulp error (assuming python uses rounding mode aware
> integer conversion like rint)
> our old (windows compiler only) fallback did not have this property as it
> had a too large error.
>
> it is of course a very bad idea to base your program around this specific
> behavior of a log + int cast
> I would not be surprised when this test fails on a bunch of platforms.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/numpy/numpy/pull/4790/files#r13520200>.
>



-- 
Nathaniel J. Smith
Postdoctoral researcher - Informatics - University of Edinburgh
http://vorpus.org