Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Apr 96 9:28:18 METDST
From:      stein@ife.no (Stein Morten Sandbech)
To:        tim@sarc.city.ac.uk
Cc:        questions@freebsd.org
Subject:   Division error in javac / kaffe ?
Message-ID:  <9604090728.AA17909@tigern.ife.no>

next in thread | raw e-mail | index | archive | help
Hi ...

I am fairly new to java, but I grabbed kaffe, version 0.54, for FreeBSD 2.1R
just a couple of days ago.

After testing some of the examples that are included in the package, I proceeded
to test some code from the book "Java" by Tim Ritchey, and some of my own.

I then stumbled on an error (can't be anything else can it ...?) regarding 
division of floats (double precision).

The code and the results are listed below:


class KaffeDivErr {
    public static void main ( String args[] ) {
	double v = 2.0, w = 5.0, W = 0.0;
        W = v / w;
        System.out.println("v = "+v);
        System.out.println("w = "+w);
	System.out.println("The division: W = v / w; yields : W="+W+"\n");

        v = 345.1223111;
        w = 1203.210943;
        W = v / w;
        System.out.println("v = "+v);
        System.out.println("w = "+w);
        System.out.println("The division: W = v / w; yields : W="+W+"\n");

        v = 12345.1223111;
        w = 1203.210943;
        W = v / w;
        System.out.println("v = "+v);
        System.out.println("w = "+w);
        System.out.println("The division: W = v / w; yields : W="+W+"\n");

        v = 12345.1223111;
        w = 1203.210943;
        W = w / v;
        System.out.println("v = "+v);
        System.out.println("w = "+w);
        System.out.println("The division: W = w / v; yields : W="+W+"\n");
    }
}


The output:

v = 2
w = 5
The division: W = v / w; yields : W=2.5

v = 345.122
w = 1203.21
The division: W = v / w; yields : W=3.48633

v = 12345.1
w = 1203.21
The division: W = v / w; yields : W=0.0974645

v = 12345.1
w = 1203.21
The division: W = w / v; yields : W=10.2601


Correct me if I'm wrong, but this does not seem right :-)

Stein Morten


/*  Stein M Sandbech                             Email: stein@ife.no          **
**  Owner & technical manager                    Email: steinms@oslonett.no   **
**  Ing. Stein M. Sandbech                       Phone: +47 6387 2300         **
**                                               Phone: +47 6380 6219         **
**  Asaktoppen 39, N-2045 Leirsund, NORWAY       Fax: +47 6381 1168           */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9604090728.AA17909>