BigDecimal ulp() Method in Java
The java.math.BigDecimal.ulp() is an inbuilt method in Java that returns the size of an ulp(unit in the last place) of this BigDecimal.
- An ulp of a nonzero BigDecimal value is defined as the positive distance between this value and the BigDecimal value next larger in magnitude with the same number of digits.
- An ulp of a zero value is numerically equal to 1 with the scale of this. The result is stored with the same scale as this so the result for zero and nonzero values is equal to [1, this.scale()].
public BigDecimal ulp()
Parameter: The method does not accept any parameter.
Return value: This method returns the size of an ulp of BigDecimal.
Input: 4.25 Output: 0.01 Input: 1789 Output: 1
Below programs illustrates the above mentioned method:
ULP value of 1789 is 1 ULP value of 4.25 is 0.01
ULP value of 78645 is 1 ULP value of 4.252547 is 0.000001
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.