More complete fix for EQUALP operations on numeric tower.

Thanks to Massimiliano Ghilardi.
parent 56638363
......@@ -213,20 +213,8 @@ public final class Bignum extends LispInteger
@Override
public boolean equalp(LispObject obj)
{
if (obj instanceof Bignum)
return value.equals(((Bignum)obj).value);
if (obj instanceof SingleFloat)
{
// 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)
{
// do not raise errors on bignums exceeding the largest representable double
double d = value.doubleValue();
return !Double.isInfinite(d) && d == ((DoubleFloat)obj).value;
}
if (obj.numberp())
return isEqualTo(obj);
return false;
}
......
......@@ -143,38 +143,8 @@ public final class Complex extends LispObject
@Override
public boolean equalp(LispObject obj)
{
if (this == obj)
return true;
if (obj instanceof Complex)
{
Complex c = (Complex) obj;
return (realpart.isEqualTo(c.realpart) &&
imagpart.isEqualTo(c.imagpart));
}
if (obj.numberp())
{
// obj is a number, but not complex.
if (imagpart instanceof SingleFloat)
{
if (((SingleFloat)imagpart).value == 0)
{
if (obj instanceof Fixnum)
return ((Fixnum)obj).value == ((SingleFloat)realpart).value;
if (obj instanceof SingleFloat)
return ((SingleFloat)obj).value == ((SingleFloat)realpart).value;
}
}
if (imagpart instanceof DoubleFloat)
{
if (((DoubleFloat)imagpart).value == 0)
{
if (obj instanceof Fixnum)
return ((Fixnum)obj).value == ((DoubleFloat)realpart).value;
if (obj instanceof DoubleFloat)
return ((DoubleFloat)obj).value == ((DoubleFloat)realpart).value;
}
}
}
return isEqualTo(obj);
return false;
}
......
......@@ -169,16 +169,8 @@ public final class DoubleFloat extends LispObject
@Override
public boolean equalp(LispObject obj)
{
if (obj instanceof SingleFloat)
return value == ((SingleFloat)obj).value;
if (obj instanceof DoubleFloat)
return value == ((DoubleFloat)obj).value;
if (obj instanceof Fixnum)
return value == ((Fixnum)obj).value;
if (obj instanceof Bignum)
return value == ((Bignum)obj).doubleValue();
if (obj instanceof Ratio)
return value == ((Ratio)obj).doubleValue();
if (obj.numberp())
return isEqualTo(obj);
return false;
}
......
......@@ -228,12 +228,8 @@ public final class Fixnum extends LispInteger
@Override
public boolean equalp(LispObject obj)
{
if (obj instanceof Fixnum)
return value == ((Fixnum)obj).value;
if (obj instanceof SingleFloat)
return value == ((SingleFloat)obj).value;
if (obj instanceof DoubleFloat)
return value == ((DoubleFloat)obj).value;
if (obj.numberp())
return isEqualTo(obj);
return false;
}
......
......@@ -137,16 +137,8 @@ public final class Ratio extends LispObject
@Override
public boolean equalp(LispObject obj)
{
if (obj instanceof Ratio) {
return numerator.equals(((Ratio)obj).numerator) &&
denominator.equals(((Ratio)obj).denominator);
}
if (obj instanceof SingleFloat) {
return floatValue() == ((SingleFloat)obj).value;
}
if (obj instanceof DoubleFloat) {
return doubleValue() == ((DoubleFloat)obj).value;
}
if (obj.numberp())
return isEqualTo(obj);
return false;
}
......
......@@ -169,16 +169,8 @@ public final class SingleFloat extends LispObject
@Override
public boolean equalp(LispObject obj)
{
if (obj instanceof SingleFloat)
return value == ((SingleFloat)obj).value;
if (obj instanceof DoubleFloat)
return value == ((DoubleFloat)obj).value;
if (obj instanceof Fixnum)
return value == ((Fixnum)obj).value;
if (obj instanceof Bignum)
return value == ((Bignum)obj).floatValue();
if (obj instanceof Ratio)
return value == ((Ratio)obj).floatValue();
if (obj.numberp())
return isEqualTo(obj);
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