Java/JDK 6/Floating Point Number

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

Math.copySign

   <source lang="java">

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

       </source>
   
  
 
  



Math.getExponent

   <source lang="java">

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

       </source>
   
  
 
  



Math.nextAfter

   <source lang="java">

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

       </source>
   
  
 
  



Math.nextUp

   <source lang="java">

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

       </source>
   
  
 
  



Math.scalb

   <source lang="java">

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

       </source>