Java Math.ulp() method

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

Test it Now

Output:

1.7763568394002505E-15

Example 2

Test it Now

Output:

7.105427357601002E-15

Example 3

Test it Now

Output:

Infinity

Example 4

Test it Now

Output:

4.9E-324

Example 5

Test it Now

Output:

1.9958403095347198E292

Example 6

Test it Now

Output:

2.028241E31

Next TopicJava Math




Latest Courses