Java Mathulp() Method
Example
Find the unit of least precision for different numbers:
System.out.println(Math.ulp(1.0));System.out.println(Math.ulp(1.0f));System.out.println(Math.ulp(5000000.0));System.out.println(Math.ulp(5000000.0f));System.out.println(Math.ulp(50000000.0));System.out.println(Math.ulp(50000000.0f));Definition and Usage
Theulp() method returns the unit of least precision of a number.
The unit of least precision is the smallest step you can take up or down from a number. For example, the ulp for50000000.0f is 4.0, so the next number above it than can be represented with afloat data type is50000004.0f.
Note: Thedouble data type has a lot more precision than thefloat data type, so the ulp is smaller.
Note: Larger numbers have less precision than smaller numbers, that means the ulp is larger.
Note: The sign of a number does not affect the ulp.
Syntax
public static double ulp(doublenumber)public static float ulp(floatnumber)Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A floating point number. |
Technical Details
| Returns: | Adouble orfloat value representing the unit of least precision. |
|---|---|
| Java version: | 1.5+ |
❮ Math Methods

