public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* java/7833: Problem multiplying int and long when int is too small for result
@ 2002-09-04 22:56 Martin Kahlert
  0 siblings, 0 replies; only message in thread
From: Martin Kahlert @ 2002-09-04 22:56 UTC (permalink / raw)
  To: gcc-gnats


>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:


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-09-05  5:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-04 22:56 java/7833: Problem multiplying int and long when int is too small for result Martin Kahlert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).