Home | History | Annotate | Download | only in math
      1 package com.google.common.math;
      2 
      3 import static com.google.common.math.MathTesting.ALL_BIGINTEGER_CANDIDATES;
      4 import static com.google.common.math.MathTesting.ALL_DOUBLE_CANDIDATES;
      5 import static com.google.common.math.MathTesting.EXPONENTS;
      6 import static com.google.common.math.MathTesting.FINITE_DOUBLE_CANDIDATES;
      7 
      8 import java.math.BigInteger;
      9 
     10 import junit.framework.TestCase;
     11 import sun.misc.FpUtils;
     12 
     13 public class DoubleUtilsTest extends TestCase {
     14   public strictfp void testScalbPositiveExponent() {
     15     for (int k : EXPONENTS) {
     16       for (double d : ALL_DOUBLE_CANDIDATES) {
     17         assertEquals(d * StrictMath.pow(2.0, k), DoubleUtils.scalb(d, k));
     18       }
     19     }
     20   }
     21 
     22   public void testGetExponent() {
     23     for (double d : ALL_DOUBLE_CANDIDATES) {
     24       assertEquals(FpUtils.getExponent(d), DoubleUtils.getExponent(d));
     25     }
     26   }
     27 
     28   public void testNextUp() {
     29     for (double d : FINITE_DOUBLE_CANDIDATES) {
     30       assertEquals(FpUtils.nextUp(d), DoubleUtils.next(d, true));
     31     }
     32   }
     33 
     34   public void testNextDown() {
     35     for (double d : FINITE_DOUBLE_CANDIDATES) {
     36       assertEquals(FpUtils.nextDown(d), DoubleUtils.next(d, false));
     37     }
     38   }
     39 
     40   public void testBigToDouble() {
     41     for (BigInteger b : ALL_BIGINTEGER_CANDIDATES) {
     42       assertEquals(b.doubleValue(), DoubleUtils.bigToDouble(b));
     43     }
     44   }
     45 }
     46