Java – how do you get the smallest possible next or previous double value supported by the architecture?
Suppose I have a bivariate D. is there any way to get the next or previous value supported by the CPU architecture
As a simple example, if the value is 10.1245125 and the precision of the schema is fixed to 7 decimal places, the next value will be 10.1245126 and the previous value will be 10.1245124
Obviously, this is not so simple in floating point architecture How can I achieve this goal (in Java)?
Solution
In fact, the IEEE 754 floating-point architecture makes this simple: due to the standard, this function is called nextafter in almost all languages that support it. This consistency enables me to write answers to your questions with little familiarity with Java:
Keep in mind that - infinity and infinity are floating-point values that are easy to give directions (second parameter) Don't act like math For common errors such as nextafter (x, x 1), only ULP with 1 greater than x is valid
Anyone who wrote the above may replace it with math Nextafter (x, double. Positive_infinity), which saves an addition and applies to all values of X