This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: problem(?) using java.lang.Float in arithmetic operation
- From: Per Bothner <per at bothner dot com>
- To: cr blimp <crblimp at yahoo dot com>
- Cc: kawa at sourceware dot org
- Date: Thu, 19 Jul 2007 09:49:41 -0700
- Subject: Re: problem(?) using java.lang.Float in arithmetic operation
- References: <598091.18466.qm@web58410.mail.re3.yahoo.com>
cr blimp wrote:
One question -
I'm extracting a single float from a java float[]
array returned
from said library. It appears that when such a float
is passed to "-", i.e.:
(set! arr (java-library-returns-float))
(set! x (arr 0))
(set! y (- x))
there is a type error -
procedure main throws exception
java.lang.ClassCastException: java.lang.Float
Invalid parameter, was: java.lang.Float
Looks like a semi-bug in gnu.kawa.functions.AddOp.
You'll note that apply2 (binary minues) has special
code to handle FLOAT_CODE. However, the unary
version $MN(Object) casts the object to Numeric, without
trying to handle the other possibilities. Hence,
the ClassCastException.
So one work-around might be to do:
(set! y (- 0 x))
Is there a function to convert a java.lang.Float to a
scheme real?
You could probably apply the doubleValue method:
(let ((x :: <java.lang.Float> arr 0))
(- (x:doubleValue x)))
(This is untested.)
If not, I could redefine all the basic arithmetic
operations
as calls to java. Is this the appropriate approach?
The best solution is to extend $Mn(Object) to match the
switch in apply2(int plusOrMinus, Object arg1, Object arg2).
--
--Per Bothner
per@bothner.com http://per.bothner.com/