Commit 109622b8 by Dakror

### calculated some magic numbers and some comments

parent 8332920d
 ... ... @@ -19,7 +19,7 @@ public class FastMath { * In literature, several of those constants for floats or doubles can be * found. There's no optimal constant for all cases. */ private static int MAGIC_NUMBER = 1024; private static int MAGIC_NUMBER = 0x534; /** * belegt die MAGIC_NUMBER mit dem Wert magic ... ...
 ... ... @@ -13,7 +13,7 @@ import javax.swing.JFrame; public class Test_FastInverse { /** Beispielwerte fuer IEEE Standard mit 32 Bits */ private static int MAGIC_NUMBER = 0x5f3759df; private static int MAGIC_NUMBER = 0x5f34c48d;//0x5f3759df; private static int anzBitsExponent = 8; private static int anzBitsMantisse = 24; ... ... @@ -64,8 +64,8 @@ public class Test_FastInverse { double step = 10. / runs; double error = 0; if(!maxError) error = Double.MAX_VALUE; if (!maxError) error = Double.MAX_VALUE; for (int i = 1; i <= runs; i++) { Gleitpunktzahl g = new Gleitpunktzahl(step * i); ... ... @@ -73,7 +73,7 @@ public class Test_FastInverse { if (maxError) { if (e > error) error = e; } else { if (e < error) error = e; if (e < error) error = e; } } ... ... @@ -91,11 +91,10 @@ public class Test_FastInverse { err = getError(magic, true); } // schaut nach links (auf dem Zahlenstrahl) for (int i = magic >> 1; i >= 1; i >>= 1) { int m = magic - i; if (m < 100000) continue; if (m < 10) continue; double e = getError(m, true); if (e < err) { return magicNumberByRecursion(m, e); ... ... @@ -132,23 +131,37 @@ public class Test_FastInverse { int magic = 0; magic = magicNumberByBruteForce(); System.out.println("Brute force: 0x" + Integer.toHexString(magic) + ", min=" + getError(magic, false)+", max="+getError(magic, true)); magic = magicNumberByRecursion(Integer.MAX_VALUE, 0); System.out.println("Recursively: 0x" + Integer.toHexString(magic) + ", min=" + getError(magic, false)+", max="+getError(magic, true)); System.out.println("Brute force: 0x" + Integer.toHexString(magic) + ", min=" + getError(magic, false) + ", max=" + getError(magic, true)); // This for loop can be used to find more similar or as good magic numbers // for (int i = 0; i < 10; i++) { // if(magic < 10) break; magic = magicNumberByRecursion(magic >> 1, 0); System.out.println("Recursively: 0x" + Integer.toHexString(magic) + ", min=" + getError(magic, false) + ", max=" + getError(magic, true)); // } System.out.println("============"); System.out.println("Final magic number: 0x" + Integer.toHexString(magic)); // There are several numbers with exact the same errors, e.g. for 8+4b: /* * Recursively: 0x17cdd534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x5f37534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x8db534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x1dd534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x77534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x1534, min=1.277523355848187E-4, max=0.18986596360536456 Recursively: 0x534, min=1.277523355848187E-4, max=0.18986596360536456 */ // Best i've found: //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // 0x5f34c48d, min=3.4021026931174703E-6, max=0.17798628049464593 // //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // iEEE: 0x5f34c48d, min=3.4021026931174703E-6, max=0.17798628049464593 // // 8+4b: 0x371ff534, min=1.277523355848187E-4, max=0.18986596360536456 // ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// FastMath.setMagic(magic); int numOfSamplingPts = 1001; ... ...
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!