[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-jel] expression problem
From: |
Konstantin L. Metlov |
Subject: |
Re: [Help-jel] expression problem |
Date: |
Thu, 10 Oct 2002 11:27:18 +0200 (CEST) |
Dear Niket,
This your expression gives unexpected result because of an integer
overflow, which is unrelated to JEL. The problem is that 222222*10000 is
not representable by 32-bit Java type "int" (whose largest value is
2147483647=0x7fffffff). When such a big numbers are encountered (with
more than 32 bits required for their representation) the highest not
fitting bits are discarded.
java Calculator 222222*10000
-2072747296
To solve the problem you can either use a java "long" type
java Calculator 222222*100000L
22222200000 ^
|
+---- please note this.
(which holds 64 bits and whose maximum value is
9223372036854775807=0x7fffffffffffffff), or, if you expect even bigger
numbers in your application, "double" type
java Calculator 222222*100000.0
2.22222E10
. The arithmetics with "double" numbers is not exact and the least
significant bits in the mantissa can be lost.
The support of arbitrary-precision arithmetics is out of scope of the
current version of JEL. Such support can be added, though (for a fee, if
someone needs it within a specified timeframe).
With the best regards,
Konstantin.