Java Math ulp() Method

The ulp() method of Java Math class returns the size of an ulp of the argument.

Syntax:

  1. public static double ulp(double x)
  2. public static float ulp(float x)

Parameters:

The parameter ‘x’ represents the floating-point number whose ulp is to be determined.

Return Value:

The ulp() method returns the size of an ulp of the argument.

  • It returns zero with same sign as argument, if the argument passed is zero.
  • It returns positive infinity, if the argument is positive or negative infinity.
  • It returns Double.MIN_VALUE, if the double at argument is negative or positive zero.
  • It returns Float.MIN_VALUE, if the float argument is negative or positive zero.
  • It returns a value equal to 2104, if the argument is ±MAX_VALUE.
  • It returns a value equal to 2971, if the argument is ±MAX_VALUE

 Example 1:

Output:

Example 2:

Output:

Example 3:

Output:

Example 4:

Output:

Example 5:

Output: