bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java Math ulp() Method

Flash cards

Review the key moves

1/4
Core idea

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.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___.out.println(Math.ulp(1.0));
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The ulp() method returns the unit of least precision of a number.
Definition and Usage
Java Math ulp() Method

❮ 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

ParameterDescription
numberRequired. A floating point number.

Technical Details

Returns:A double or float value representing the unit of least precision.
Java version:1.5+

Previous

Java Math toRadians() Method

Next

Java Output Methods