VOOZH about

URL: https://www.geeksforgeeks.org/java/strictmath-ulp-method-in-java-with-examples/

⇱ StrictMath ulp() Method In Java with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

StrictMath ulp() Method In Java with Examples

Last Updated : 13 Dec, 2021

ulp(double num)

The ulp(double num) is an inbuilt method of StrictMath class in java which is used to get the size of an ulp of the given argument. An ulp of a double value is the positive distance between this floating point value and the double value which is next larger in magnitude.
Some special cases are: 

  • The result is NaN, if the argument is NaN.
  • The result is positive infinity, if the argument is positive or negative infinity.
  • The result is Double.MIN_VALUE if the argument is positive or negative zero.
  • The result is equal to 2^971 if the argument is ±Double.MAX_VALUE.


Syntax:  

public static double ulp(double num)


Parameters: The method accepts one parameter num of double type the floating-point value whose ulp is to be returned.
Return Value: The ulp method returns the size of an ulp of the argument.
Examples:  

Input: num = 5.7
Output: 8.881784197001252E-16

Input: num = 0.0
Output: 4.9E-324


Below program illustrates the java.lang.StrictMath.ulp() method:
Program 1:  


Output: 
 The Size of ulp of 9.7 = 1.7763568394002505E-15
 The Size of ulp of 4.9 = 8.881784197001252E-16

 

ulp(float num)

The ulp(float num) is an inbuilt method of StrictMath class in java which is used to get the size of an ulp of the given argument. An ulp of a float value is the positive distance between this floating point value and the float value which is next larger in magnitude.
Some special cases are:

  • The result is NaN, if the argument is NaN.
  • The result is positive infinity, if the argument is positive or negative infinity.
  • The result is Float.MIN_VALUE if the argument is positive or negative zero.
  • The result is equal to 2^104 if the argument is ±Float.MAX_VALUE.


Syntax:  

public static float ulp(float num)


Parameters: The method accepts one parameter num of float type the floating-point value whose ulp is to be returned.
Return Value: The ulp method returns the size of an ulp of the argument.
Examples: 

Input: num = 5.7
Output: 8.881784197001252E-16

Input: num = 0.0
Output: 4.9E-324


Below program illustrates the java.lang.StrictMath.ulp() method:
Program 1:  


Output: 
 The Size of ulp of 2.7 = 2.3841858E-7
 The Size of ulp of -4.5 = 4.7683716E-7

 
Comment