The java.lang.Math.ulp() is a built-in java method which returns the size of an ulp of the argument.An ulp stands for unit of least precision.It calculates the distance between the given double or float value and the
double or float value next larger in magnitude.
Arguments can be of two types :
- ulp(float f) :It takes input of float type.
- ulp(double d) :It takes input of double type.
- If the argument is NaN, Output is NaN.
- If the argument is positive or negative double or float value, Output for ulp(-arg) and ulp(arg) is same.
- If the argument is positive or negative Zero, Output will be Double.MIN_VALUE or Float.MIN_VALUE.
- If the argument is positive or negative infinity, Output is positive infinity.
- If the argument is positive or negative Double.MAX_VALUE or Float.MAX_VALUE, Output will be 2971 for double type and 2104 for float type.
public static dataType ulp(dataType g) Parameter : g: argument whose ulp is to be returned. Return : This method returns the size of an ulp of the argument.
Example :To show working of java.lang.Math.ulp() method.
7.105427357601002E-15 7.105427357601002E-15 NaN 1.4E-45 Infinity 1.9958403095347198E292
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- HashSet vs TreeSet in Java
- ShortBuffer allocate() method in Java With Examples
- IntBuffer duplicate() method in Java with Examples
- ShortBuffer compact() method in Java With Examples
- LongBuffer equals() method in Java
- IntBuffer array() method in Java
- IntBuffer hasArray() method in Java
- ShortBuffer arrayOffset() method in Java With Examples
- ShortBuffer asReadOnlyBuffer() method in Java with Examples
- ByteBuffer asDoubleBuffer() method in Java with Examples