Flash cards
Review the key moves
What is the main idea behind Java Math ulp() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
___.out.println(Math.ulp(1.0));Put the learning moves in the order that makes the concept easiest to apply.
❮ Math Methods
Example
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
The ulp() 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 for 50000000.0f is 4.0, so the next number above it than can be represented with a float data type is 50000004.0f .
Note
The double data type has a lot more precision than the float 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(double
number )public static float ulp(float
number )Parameter Values
| Parameter | Description |
|---|---|
| number | Required. A floating point number. |
Technical Details
| Returns: | A double or float value representing the unit of least precision. |
|---|---|
| Java version: | 1.5+ |