|
From: <bc...@wo...> - 2001-03-27 08:37:30
|
[Pilho Kim]
>I have meet Jython's wrong calculation about complex numbers.
>
>Check the results of the following example.
>
>Regards,
>Kim
>
>
>
>"""
> test.py
>"""
>
>z = 2.0 + 1.0j
>
>for i in range(1, 101):
> print "%s^%d = %s" % (z, i, z**i)
>
>
>
>[Result on Python 2.0]
>(2+1j)^55 = (1.55453313831e+019+5.99152971656e+018j)
>
>[Result on Jython 2.0 or Jython 2.1 alpha 1]
>(2+1j)^55 = (9223372036854775807+5991529716557069312j)
I think I have tracked it down to PyComplex.toString():
public static String toString(double value) {
if (value == Math.floor(value)) {
return Long.toString((long)value);
} else {
return Double.toString(value);
}
}
Changing that method to:
public static String toString(double value) {
if (value == Math.floor(value) &&
value < Long.MAX_VALUE && value > Long.MIN_VALUE) {
return Long.toString((long)value);
} else {
return Double.toString(value);
}
}
seems to work for the test program, but my understanding of the finer
points of FP and complex numbers is zero. I hope somebody else with a
better understanding of this can verify that it is the intended
behaviour.
regards,
finn
|