Java/JDK 6/Floating Point Number

Материал из Java эксперт
Перейти к: навигация, поиск

Math.copySign

 
public class FloastPointDemo {
  public static void main(String[] args) {
    // Returns a copySign of the first argument
    double d = Math.copySign (1234.56, -1);
    System.out.println ("Math.copySign (1234.56, -1) = " + d);
  }
}
// Math.copySign (1234.56, -1) = -1234.56





Math.getExponent

 
public class FloastPointDemo {
    public static void main (String[] args) {
      // Returns the unbiased exponent value of a double,
      // where 2^exp <= d. In this case, 2^4 <= 17
      int exp = Math.getExponent (17.0);
      System.out.println ("Math.getExponent (17.0) = " + exp);
    }
}
//Math.getExponent (17.0) = 4





Math.nextAfter

 

public class FloastPointDemo {
  public static void main(String[] args) {
    // Returns the lesser adjacent of a double
    double lesserAdjacent = Math.nextAfter(123.0, 120.0);
    System.out.println("Math.nextAfter (123.0, 120.0) = " + lesserAdjacent);
  }
}
// Math.nextAfter (123.0, 120.0) = 122.99999999999999





Math.nextUp

 

public class FloastPointDemo {
  public static void main(String[] args) {
    // Returns the greater adjacent of a double
    double greaterAdjacent = Math.nextUp(123.0);
    System.out.println("Math.nextUp (123.0) = " + greaterAdjacent);
  }
}
// Math.nextUp (123.0) = 123.00000000000001





Math.scalb

 
public class FloastPointDemo {
    public static void main (String[] args) {
        // Returns 12.0 x (2^3)
        double scalbResult = Math.scalb (12.0, 3);
        System.out.println ("Math.scalb (12.0, 3) = " + scalbResult);
    }
}
//Math.scalb (12.0, 3) = 96.0