This is the mail archive of the
java-discuss@sources.redhat.com
mailing list for the Java project.
Re: Don't optimize by hand (Was Re: Lack of fabsf on Solaris(patch included))
Andrew Haley wrote:
> > And we probably don't really implement strict fp
> > semantics anyway
>
> The last time that I ran any tests we were 100% strict fp perfect.
> That's better than the other Java implementation I tried!
>
> Andrew.
Here is a test program.
If the Java runtime is compliant with the strictfp specification,
you will see the following:
% java StrictfpTest
shuJIT for Sun Classic VM/x86 by Kazuyuki Shudo
1.112808544714844E-308 (0x0008008000000000)
* 1.0000000000000002 (0x3ff0000000000001)
default : 1.112808544714844E-308 (0x8008000000000)
strictfp: 1.1128085447148447E-308 (0x8008000000001)
2.225073858507201E-308 (0x000fffffffffffff)
/ 0.9999999999999999 (0x3fefffffffffffff)
default : 2.2250738585072014E-308 (0x10000000000000)
strictfp: 2.225073858507201E-308 (0xfffffffffffff)
I guess the FP semantics has not been implemented on GCJ yet.
Kazuyuki SHUDO Happy Hacking!
Muraoka Laboratory, Waseda University
class StrictfpTest {
private static double defaultDmul(double a, double b) {
return a * b;
}
private static strictfp double strictDmul(double a, double b) {
return a * b;
}
private static double defaultDdiv(double a, double b) {
return a / b;
}
private static strictfp double strictDdiv(double a, double b) {
return a / b;
}
public static void main(String[] args) {
double a, b, c;
/* multiplication */
a = Double.longBitsToDouble(0x0008008000000000L);
b = Double.longBitsToDouble(0x3ff0000000000001L);
System.out.println(a + " (0x0008008000000000)");
System.out.println(" * " + b + " (0x3ff0000000000001)");
c = defaultDmul(a, b);
System.out.println("default : " + c +
" (0x" + Long.toHexString(Double.doubleToLongBits(c)) + ")");
c = strictDmul(a, b);
System.out.println("strictfp: " + c +
" (0x" + Long.toHexString(Double.doubleToLongBits(c)) + ")");
System.out.println();
/* division */
a = Double.longBitsToDouble(0x000fffffffffffffL);
b = Double.longBitsToDouble(0x3fefffffffffffffL);
System.out.println(a + " (0x000fffffffffffff)");
System.out.println(" / " + b + " (0x3fefffffffffffff)");
c = defaultDdiv(a, b);
System.out.println("default : " + c +
" (0x" + Long.toHexString(Double.doubleToLongBits(c)) + ")");
c = strictDdiv(a, b);
System.out.println("strictfp: " + c +
" (0x" + Long.toHexString(Double.doubleToLongBits(c)) + ")");
}
}