[armedbear-cvs] r12951 - trunk/abcl/src/org/armedbear/lisp
Erik Huelsmann
ehuelsmann at common-lisp.net
Mon Oct 4 13:11:13 UTC 2010
Author: ehuelsmann
Date: Mon Oct 4 09:11:12 2010
New Revision: 12951
Log:
Signal a condition when coercing a Ratio to any float type or when
coercing a double-float to a single-float where the original value
is too big to fit the target type.
Modified:
trunk/abcl/src/org/armedbear/lisp/Ratio.java
trunk/abcl/src/org/armedbear/lisp/SingleFloat.java
Modified: trunk/abcl/src/org/armedbear/lisp/Ratio.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/Ratio.java (original)
+++ trunk/abcl/src/org/armedbear/lisp/Ratio.java Mon Oct 4 09:11:12 2010
@@ -181,6 +181,10 @@
@Override
public float floatValue()
{
+ float result = (float) doubleValue();
+ if (Float.isInfinite(result) && TRAP_OVERFLOW)
+ type_error(this, Symbol.SINGLE_FLOAT);
+
return (float) doubleValue();
}
@@ -217,6 +221,9 @@
n = n.shiftRight(1);
d = d.shiftRight(1);
}
+ if (Double.isInfinite(result) && TRAP_OVERFLOW)
+ type_error(this, Symbol.DOUBLE_FLOAT);
+
return negative ? -result : result;
}
Modified: trunk/abcl/src/org/armedbear/lisp/SingleFloat.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/SingleFloat.java (original)
+++ trunk/abcl/src/org/armedbear/lisp/SingleFloat.java Mon Oct 4 09:11:12 2010
@@ -629,8 +629,13 @@
return new SingleFloat(((Fixnum)obj).value);
if (obj instanceof SingleFloat)
return (SingleFloat) obj;
- if (obj instanceof DoubleFloat)
- return new SingleFloat((float)((DoubleFloat)obj).value);
+ if (obj instanceof DoubleFloat) {
+ float result = (float)((DoubleFloat)obj).value;
+ if (Float.isInfinite(result) && TRAP_OVERFLOW)
+ type_error(obj, Symbol.SINGLE_FLOAT);
+
+ return new SingleFloat(result);
+ }
if (obj instanceof Bignum)
return new SingleFloat(((Bignum)obj).floatValue());
if (obj instanceof Ratio)
More information about the armedbear-cvs
mailing list