Math.ulp()
Java Math.ulp() method
Last Updated : 17 Mar 2025
The java.lang.Math.ulp() returns the size of an ulp of the argument. An ulp is the unit in the last place. An ulp of a float or double value is the positive distance between given value and the next value that is larger in magnitude.
Note: For non-NaN x, ulp(-x) == ulp(x).
Syntax
Parameter
Return
- If the argument is positive or negative double or float value, this method will return the output.
- If the argument is positive or negative Infinity, this method will return positive Infinity.
- If the argument is positive or Negative Zero, this method will return Double.MIN_VALUE.
- If the argument is Double.MAX_VALUE, this method will return the result equal to 2971.
- If the argument is Float.MAX_VALUE, this method will return the result equal to 2104.
- If the argument is NaN, this method will return NaN.
Example 1
Output:
Example 2
Output:
Example 3
Output:
Example 4
Output:
Example 5
Output:
Example 6
Output: