[Sablevm-developer] problem with divisions, float, double
Brought to you by:
egagnon
From: Fabien R. <re...@ne...> - 2004-05-13 07:27:01
|
Hello, With Arith.java I have some problem with numbers : [verbose class: loading "Arith"] iadd [verbose class: loading "java/lang/Integer"] [verbose class: loading "java/lang/Number"] = 4 isub = 2 imul = 3 idiv = 3 irem = 0 ineg = -3 ladd [verbose class: loading "java/lang/Long"] = 4 lsub = 2 lmul = 3 ldiv = 3 lrem = 0 lneg = -3 fadd [verbose class: loading "java/lang/Float"] [verbose class: loading "java/lang/Double"] = 3.0 fsub = 3.0 fmul = 0.0 fdiv [verbose gc: previously allocated 16777180 bytes, surviving 56040 bytes, new heap is 16777216 bytes, gc time = 0 sec 9971 usec] [verbose gc: previously allocated 16777208 bytes, surviving 55972 bytes, new heap is 16777216 bytes, gc time = 0 sec 8790 usec] [verbose gc: previously allocated 16777192 bytes, surviving 55980 bytes, new heap is 16777216 bytes, gc time = 0 sec 9381 usec] Kaffe too has problems (crashs when there is a double) This is the source : public class Arith { static int add(int a, int b) { return a + b; } static int sub(int a, int b) { return a - b; } static int mul(int a, int b) { return a * b; } static int div(int a, int b) { return a / b; } static int rem(int a, int b) { return a % b; } static int neg(int a) { return -a; } static long add(long a, long b) { return a + b; } static long sub(long a, long b) { return a - b; } static long mul(long a, long b) { return a * b; } static long div(long a, long b) { return a / b; } static long rem(long a, long b) { return a % b; } static long neg(long a) { return -a; } static float add(float a, float b) { return a + b; } static float sub(float a, float b) { return a - b; } static float mul(float a, float b) { return a * b; } static float div(float a, float b) { return a / b; } static float rem(float a, float b) { return a % b; } static float neg(float a) { return -a; } static double add(double a, double b) { return a + b; } static double sub(double a, double b) { return a - b; } static double mul(double a, double b) { return a * b; } static double div(double a, double b) { return a / b; } static double rem(double a, double b) { return a % b; } static double neg(double a) { return -a; } public static void main (String[] args) { test_int (3, 1); test_long (3, 1); test_float (3, 0); test_double (3, 0); System.out.println("Done!"); } static void test_int(int a, int b) { char prefix = 'i'; System.out.println(prefix + "add"); System.out.println("\t= " + add(a,b)); System.out.println(prefix + "sub"); System.out.println("\t= " + sub(a,b)); System.out.println(prefix + "mul"); System.out.println("\t= " + mul(a,b)); System.out.println(prefix + "div"); System.out.println("\t= " + div(a,b)); System.out.println(prefix + "rem"); System.out.println("\t= " + rem(a,b)); System.out.println(prefix + "neg"); System.out.println("\t= " + neg(a)); } static void test_long(long a, long b) { char prefix = 'l'; System.out.println(prefix + "add"); System.out.println("\t= " + add(a,b)); System.out.println(prefix + "sub"); System.out.println("\t= " + sub(a,b)); System.out.println(prefix + "mul"); System.out.println("\t= " + mul(a,b)); System.out.println(prefix + "div"); System.out.println("\t= " + div(a,b)); System.out.println(prefix + "rem"); System.out.println("\t= " + rem(a,b)); System.out.println(prefix + "neg"); System.out.println("\t= " + neg(a)); } static void test_float(float a, float b) { char prefix = 'f'; System.out.println(prefix + "add"); System.out.println("\t= " + add(a,b)); System.out.println(prefix + "sub"); System.out.println("\t= " + sub(a,b)); System.out.println(prefix + "mul"); System.out.println("\t= " + mul(a,b)); System.out.println(prefix + "div"); System.out.println("\t= " + div(a,b)); System.out.println(prefix + "rem"); System.out.println("\t= " + rem(a,b)); System.out.println(prefix + "neg"); System.out.println("\t= " + neg(a)); } static void test_double(double a, double b) { char prefix = 'd'; System.out.println(prefix + "add"); System.out.println("\t= " + add(a,b)); System.out.println(prefix + "sub"); System.out.println("\t= " + sub(a,b)); System.out.println(prefix + "mul"); System.out.println("\t= " + mul(a,b)); System.out.println(prefix + "div"); System.out.println("\t= " + div(a,b)); System.out.println(prefix + "rem"); System.out.println("\t= " + rem(a,b)); System.out.println(prefix + "neg"); System.out.println("\t= " + neg(a)); } } If someone has an idea ... Cheers, Fabien |