This is the mail archive of the
java-prs@gcc.gnu.org
mailing list for the Java project.
java/7833: Problem multiplying int and long when int is too small for result
- From: Martin Kahlert <martin dot kahlert at infineon dot com>
- To: gcc-gnats at gcc dot gnu dot org
- Date: Thu, 5 Sep 2002 07:48:15 +0200
- Subject: java/7833: Problem multiplying int and long when int is too small for result
- Reply-to: Martin dot Kahlert at infineon dot com
>Number: 7833
>Category: java
>Synopsis: Bug in multiplying int and long when int is too small for result
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed Sep 04 22:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Martin Kahlert
>Release: 3.2.1 20020902 (prerelease)
>Organization:
Infineon AG
>Environment:
System: Linux keksy 2.4.19 #1 SMP Mon Sep 2 12:45:32 MEST 2002 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-20020902/configure --prefix=/usr/local/snapshots --enable-languages=f77,c++,java --disable-threads --enable-shared=libstdc++
>Description:
Multiplication of an int with a long results in wrong result
when the result does not fit into an int.
The hex output of a large long looks suspicious, too!
>How-To-Repeat:
$ cat hello.java
public class hello
{
final static long a = 1000000000;
final static long b = 1000 * a;
final static long c = 1000L * a;
public static void main(String[] args)
{
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
}
}
$ gcj -o hello hello.java --main=hello
$ ./hello
a = 1000000000
b = -727379968
c = 0xe8d4a51000
Workaround: Use longs (i.e. 1000L instead of 1000 or proper casts).
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: