[kaffe] Simple program shows strange results

Ito Kazumitsu kaz at maczuka.gcd.org
Mon Mar 3 08:58:01 PST 2003


The following program:

public class Test {
  public static void main(String[] args) {
      float x = 0f;

      float pb = 15.0f;
      float pc = 2.0f;
      float pd = 6.0f;
      float pe = 7.0f;
      float pf = 9.0f;
          
      x = (1.0f - (pc / pd)) * pb;
      System.err.println(x);
      if (x < pe) {
        System.err.println("x<pe: " + x + " " + pe);
        x = pe;
      }
      else if (x > pf) {
        System.err.println("x>pf: " + x + " " + pf);
        x = pf;
      }
      System.err.println("x pe pf =" + x + " " + pe + " "+ pf);
  }
}

shows the following output when run with j2sdk1.4.0:

bash$ java Test
9.999999
x>pf: 9.999999 9.0
x pe pf =9.0 7.0 9.0

which is what I expect.  But when run with kaffe, it shows:

bash-2.05b$ java Test
9.999999
x<pe: 0.0 7.0
x pe pf =7.0 7.0 9.0

The kaffe version is

Engine: Just-in-time v3   Version: 1.1.x-cvs   Java Version: 1.1
Configuration/Compilation options:
  Compile date  : Sun Feb 23 11:17:00 JST 2003
  Compile host  : ph.maczuka.gcd.org
  Install prefix: /usr/local/kaffe
  Thread system : unix-jthreads
  CC            : gcc
  CFLAGS        : -g -O2 -Wall -Wstrict-prototypes
  LDFLAGS       : 
  ChangeLog head: 2003-02-12 Dalibor Topic <robilad at yahoo.com>

By the way,  changing the said program as follows, that is
changing the System.err.println(x) to System.err.println("x=" + x),
I get expected output.

public class Test {
  public static void main(String[] args) {
      float x = 0f;

      float pb = 15.0f;
      float pc = 2.0f;
      float pd = 6.0f;
      float pe = 7.0f;
      float pf = 9.0f;
          
      x = (1.0f - (pc / pd)) * pb;
      System.err.println("x=" + x);
      if (x < pe) {
        System.err.println("x<pe: " + x + " " + pe);
        x = pe;
      }
      else if (x > pf) {
        System.err.println("x>pf: " + x + " " + pf);
        x = pf;
      }
      System.err.println("x pe pf =" + x + " " + pe + " "+ pf);
  }
}

bash-2.05b$ java Test
x=9.999999
x>pf: 9.999999 9.0
x pe pf =9.0 7.0 9.0

I wonder what is happening.




More information about the kaffe mailing list