[Matrix-SIG] array([19990609],'f') bug?

Tim Peters tim_one@email.msn.com
Wed, 23 Jun 1999 01:14:17 -0400


[Hoon Yoon]
> Can anyone explain this strange behavior?
> NT svcpack 3 running version 11 of NumPy
> >>> array([19990609],'f')
>        array([ 19990608.],'f')
> Anyone have a fix?

IEEE floats (single-precision) have 24 mantissa bits, so the dense range of
representable integers is [-2**24, 2**24] = [-16777216, 16777216].  Your
input number is outside that range, but is in the next larger binade (i.e.
+/- 2**25), where only every *second* integer is exactly representable (and
in the next binade after that, only every fourth integer is representable;
and in the next binade after that, only every eighth; etc).  That's why it
got chopped to an even integer.

So long as you're using floats, you'll either get 19990608 or 19990610 (ANSI
C doesn't define which one you'll get back, but the important point is that
it's impossible to get back 19990609).

so-use-doubles-or-ints-or-stick-to-float-ints-divisible-by-large-powers-
    of-2-ly y'rs  - tim