Home >>Java Math Methods >Java Math.ulp() method

Java Math.ulp() method

Java Math.ulp() method

Java Math.ulp() Method in Java Math is used to returns an ulp of the argument 's size. An ulp is the last place on the device. The positive distance between the given value and the next value which is greater in magnitude is an ulp of a float or double.

Syntax

public static double ulp(double x)  
public static float ulp(float x)  

Parameter

x = This parameter is used for a floating-point value whose ulp is to be returned

Return

It is used to returns the size of an ulp of the argument.

  1. If the argument is double or float positive or negative, this method returns the output.
  2. If the statement is Infinity positive or negative, the process should return Infinity positive.
  3. If the argument is positive or negative zero then Double. MIN VALUE will return this method.
  4. If the argument is ±Double. MAX VALUE, the result is returned equal to 2971 by this meth

Java Math.ulp() method Example 1


public class MyClass  
{  
public static void main(String[] args)   
{  
double x = 6.2;  
System.out.println(Math.ulp(x));  
}  
}  

Output:
8.881784197001252E-16

Java Math.ulp() method Example 2


public class MyClass 
{  
public static void main(String[] args)   
{  
float x = -2.0f / 0;  
System.out.println(Math.ulp(x));  
}  
}  

Output:
Infinity

No Sidebar ads