Test of pow method, of class FastMath.
()
| 138 | * Test of pow method, of class FastMath. |
| 139 | */ |
| 140 | @Test |
| 141 | public void testPow() |
| 142 | { |
| 143 | System.out.println("pow"); |
| 144 | DoubleList relErrs = new DoubleList(); |
| 145 | int trials = 10000; |
| 146 | for(int i = 0; i < trials; i++) |
| 147 | { |
| 148 | double x = rand.nextDouble()*20; |
| 149 | double y = rand.nextDouble()*20; |
| 150 | relErrs.add(relErr(Math.pow(y, x), FastMath.pow(y, x))); |
| 151 | } |
| 152 | Collections.sort(relErrs); |
| 153 | //most should have lowwer rel error for best cases |
| 154 | assertTrue(relErrs.get((int) (trials*.10)) <= 1e-4);//usually does better than this |
| 155 | assertTrue(relErrs.get((int) (trials*.50)) <= 1e-3); |
| 156 | assertTrue(relErrs.get((int) (trials*.75)) <= 1e-2); |
| 157 | assertTrue(relErrs.get((int) (trials*.95)) <= 1e-1); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Test of log method, of class FastMath. |