[Matrix-SIG] possible bug in NumPy

Zane Motteler zcm@llnl.gov
Tue, 5 May 1998 08:30:46 -0800


Hi Oliver,

You wrote:

>I think I found what looks like a bug in NumPy (I am not up to date with
>the very latest release, but I don't remember this coming up here before):
>
>Python 1.5 (#3, Feb 12 1998, 12:14:31)  [GCC 2.7.2.3] on linux2
>Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>>> from Numeric import *
>>>> a = array([[1,1],[2,2]])
>>>> b = array([[1.1,1.1],[2.1,2.1]])
>>>> c = array([[0.1,0.1],[0.1,0.1]])
>>>> abs(a-b)
>array([[0.1,0.1],
>       [0.1,0.1]])
>>>> less_equal(abs(a-b),c)
>array([[0, 0],
>       [0, 0]])
>>>> less_equal(c,abs(a-b))
>array([[1, 1],
>       [1, 1]])

It's not a bug. The problem is that .1 decimal gives a repeating
mantissa in binary (.000110001100011...) and of course cannot be
exactly represented in floating point format, which is finite
in length. 1.0001100011... will have one less bit right of the
binary point, and 10.0001100011... will have two less,
than .0001100011... so when you subtract off the integer part,
the remaining fractions will not be equal. This is a hardware,
not a software, "feature."

Cheers

Zane

-----------------------------------------------------------------
                      Zane C. Motteler, Ph. D.
Computer Scientist             | Professor Emeritus of
Lawrence Livermore National    |    Computer Science and Engineering
   Laboratory                  | California Polytechnic
P. O. Box 808, L-38 **NOTE**   |    State University
(7000 East Avenue, zip 94550)  | San Luis Obispo, CA 93407
Livermore, CA 94551-9900       | zmottel@phoenix.csc.calpoly.edu
925/423-2143, FAX 423-9969 (NOTE AREA CODE CHANGE!!)
zcm@llnl.gov