This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix (= an-IntNum a-Complex) ClassCastException


Please apply the attached patch to fix this error comparing an <integer>
to a <complex>:

#|kawa:2|# (= 0 +i)
/dev/stdin:2:1: warning - call to #<procedure => throws java.lang.ClassCastException: gnu.math.CComplex cannot be cast to gnu.math.RealNum
java.lang.ClassCastException: gnu.math.CComplex cannot be cast to gnu.math.RealNum
	at gnu.math.IntNum.compare(IntNum.java:259)
	at gnu.kawa.functions.NumberCompare.compare(NumberCompare.java:214)
	at gnu.kawa.functions.NumberCompare.compare(NumberCompare.java:147)
	at gnu.kawa.functions.NumberCompare.apply2(NumberCompare.java:123)
	at gnu.kawa.functions.NumberCompare.$Eq(NumberCompare.java:33)
	at atInteractiveLevel$2.run(stdin:2)
	at gnu.expr.ModuleExp.evalModule2(ModuleExp.java:317)
	at gnu.expr.ModuleExp.evalModule(ModuleExp.java:219)
	at kawa.Shell.run(Shell.java:291)
	at kawa.Shell.run(Shell.java:203)
	at kawa.Shell.run(Shell.java:184)
	at kawa.repl.main(repl.java:892)

The fix is to change

>   public int compare (Object obj)
>   {
>     if (obj instanceof IntNum)
>       return compare (this, (IntNum) obj);
>     return ((RealNum)obj).compareReversed (this);
>   }

to

>   public int compare (Object obj)
>   {
>     if (obj instanceof IntNum)
>       return compare (this, (IntNum) obj);
>     return ((Numeric)obj).compareReversed (this);
>   }

that is, don't assume that obj is a RealNum.

--
Jamison Hope
The PTR Group
www.theptrgroup.com


Attachment: IntNum-compare.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]