M
MrChance
Gast
Hat jemand ein Beispiel, wo eine Berechung mit strictfp ein anderes Ergebnis liefert als eine ohne strictfp. Also f(x) != strict f(x) ?
public static strictfp void main(String[] args) {
for(long i = 1; i < Long.MAX_VALUE; ++i) {
if (f1(i) != f2(i)) System.out.println("Unterschied bei "+i);
}
}
public static strictfp double f1(long x) {
return 1.0/x;
}
public static double f2(long x) {
return 1.0/x;
}
public static void main(String[] args) {
for( int i = 1; i < Integer.MAX_VALUE; ++i) {
if ( StrictMath.IEEEremainder( StrictMath.atan(i), Math.atan(i) ) > 0 ){
System.out.println("Ungleich bei " + i);
break;
}
}
}
double a = 16.0;
double b = 7.0/16.0;
System.out.print("Plattformabhängig: " + (a%b) );
System.out.println(" Plattformunabhängig: " + StrictMath.IEEEremainder(a, b) );
public class StrictTest {
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)) + ")");
}
}