Changeset 14749


Ignore:
Timestamp:
01/26/15 06:39:06 (8 years ago)
Author:
Mark Evenson
Message:

Numeric tower repairs on promoting floats across representation boundaries.

Thanks to Massimiliano Ghilardi.

If a bignum exceeds the largest representable single-float,
EQUALP will raise a type-error when comparing it to a single-float.
The same problem happens with double-floats.

I am reporting this because my understanding of CLHS
http://www.lispworks.com/documentation/lw51/CLHS/Body/f_equalp.htm#equalp
tells that EQUALP is not supposed to raise errors at all:
"Exceptional Situations: None."

How to reproduce:

;; =========== double-floats ===========
(= (ash 1 1024) most-positive-double-float)
NIL

(equalp (ash 1 1024) most-positive-double-float)
; Evaluation aborted on #<TYPE-ERROR {215F90FE}>.

;; =========== single-floats ===========
(= 340282360000000000000000000000000000000 0.0f0)
NIL

(equalp 340282360000000000000000000000000000000 0.0f0)
; Evaluation aborted on #<TYPE-ERROR {1CFFC364}>.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/Bignum.java

    r13440 r14749  
    217217      return value.equals(((Bignum)obj).value);
    218218    if (obj instanceof SingleFloat)
    219       return floatValue() == ((SingleFloat)obj).value;
    220     if (obj instanceof DoubleFloat)
    221       return doubleValue() == ((DoubleFloat)obj).value;
     219    {
     220      // do not raise errors on bignums exceeding the largest representable float
     221      float f = value.floatValue();
     222      return !Float.isInfinite(f) && f == ((SingleFloat)obj).value;
     223    }
     224    if (obj instanceof DoubleFloat)
     225    {
     226      // do not raise errors on bignums exceeding the largest representable double
     227      double d = value.doubleValue();
     228      return !Double.isInfinite(d) && d == ((DoubleFloat)obj).value;
     229    }
    222230    return false;
    223231  }
Note: See TracChangeset for help on using the changeset viewer.