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}>.
parent f7b5830d
......@@ -216,9 +216,17 @@ public final class Bignum extends LispInteger
if (obj instanceof Bignum)
return value.equals(((Bignum)obj).value);
if (obj instanceof SingleFloat)
return floatValue() == ((SingleFloat)obj).value;
{
// do not raise errors on bignums exceeding the largest representable float
float f = value.floatValue();
return !Float.isInfinite(f) && f == ((SingleFloat)obj).value;
}
if (obj instanceof DoubleFloat)
return doubleValue() == ((DoubleFloat)obj).value;
{
// do not raise errors on bignums exceeding the largest representable double
double d = value.doubleValue();
return !Double.isInfinite(d) && d == ((DoubleFloat)obj).value;
}
return false;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment