Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Most languages have intrinsic or library functions for acquiring the next or previous single-precision (32-bit) and/or double-precision (64-bit) number. </p> <p>For users of 32-bit and 64-bit floating point arithmetic, a sound understanding of the basic constructs is very useful for avoiding some hazards with them. The IEEE standard applies uniformly, but still leaves a number of details up to implementers. Hence, a platform universal solution based on bit manipulations of the machine word representations may problematic and may depend on issues such as endian and so on. Whilst understanding all the gory details of how it could or should work at the bit level may demonstrate intellectual prowess, it is still better to use an intrinsic or library solution that is tailored for each platform and has a universal API across supported platforms. </p> <p>I noticed solutions for C# and C++. Here are some for Java:</p> <p><strong>Math.nextUp:</strong></p> <p><strong>public static double nextUp(double d):</strong></p> <ul> <li>Returns the floating-point value adjacent to d in the direction of positive infinity. This method is semantically equivalent to nextAfter(d, Double.POSITIVE_INFINITY); however, a nextUp implementation may run faster than its equivalent nextAfter call.</li> </ul> <p>Special Cases: </p> <ul> <li>If the argument is NaN, the result is NaN.</li> <li>If the argument is positive infinity, the result is positive infinity.</li> <li>If the argument is zero, the result is Double.MIN_VALUE</li> </ul> <p>Parameters:</p> <ul> <li>d - starting floating-point value</li> </ul> <p>Returns:</p> <ul> <li>The adjacent floating-point value closer to positive infinity.</li> </ul> <p><strong>public static float nextUp(float f):</strong></p> <ul> <li>Returns the floating-point value adjacent to f in the direction of positive infinity. This method is semantically equivalent to nextAfter(f, Float.POSITIVE_INFINITY); however, a nextUp implementation may run faster than its equivalent nextAfter call.</li> </ul> <p>Special Cases: </p> <ul> <li>If the argument is NaN, the result is NaN. </li> <li>If the argument is positive infinity, the result is positive infinity.</li> <li>If the argument is zero, the result is Float.MIN_VALUE</li> </ul> <p>Parameters:</p> <ul> <li>f - starting floating-point value</li> </ul> <p>Returns:</p> <ul> <li>The adjacent floating-point value closer to positive infinity.</li> </ul> <p>The next two are a bit more complex to use. However, a direction towards zero or towards either positive or negative infinity seem the more likely and useful uses. Another use is to see an intermediate value exists between two values. One can determine how many exist between two values with a loop and counter. Also, it seems they, along with the nextUp methods, might be useful for increment/decrement in for loops. </p> <p><strong>Math.nextAfter:</strong></p> <p><strong>public static double nextAfter(double start, double direction)</strong></p> <ul> <li>Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal the second argument is returned.</li> </ul> <p>Special cases: </p> <ul> <li>If either argument is a NaN, then NaN is returned.</li> <li>If both arguments are signed zeros, direction is returned unchanged (as implied by the requirement of returning the second argument if the arguments compare as equal).</li> <li>If start is ±Double.MIN_VALUE and direction has a value such that the result should have a smaller magnitude, then a zero with the same sign as start is returned.</li> <li>If start is infinite and direction has a value such that the result should have a smaller magnitude, Double.MAX_VALUE with the same sign as start is returned.</li> <li>If start is equal to ± Double.MAX_VALUE and direction has a value such that the result should have a larger magnitude, an infinity with same sign as start is returned.</li> </ul> <p>Parameters:</p> <ul> <li>start - starting floating-point value</li> <li>direction - value indicating which of start's neighbors or start should be returned</li> </ul> <p>Returns:</p> <ul> <li>The floating-point number adjacent to start in the direction of direction.</li> </ul> <p><strong>public static float nextAfter(float start, double direction)</strong></p> <ul> <li>Returns the floating-point number adjacent to the first argument in the direction of the second argument. If both arguments compare as equal a value equivalent to the second argument is returned.</li> </ul> <p>Special cases: </p> <ul> <li>If either argument is a NaN, then NaN is returned. </li> <li>If both arguments are signed zeros, a value equivalent to direction is returned. </li> <li>If start is ±Float.MIN_VALUE and direction has a value such that the result should have a smaller magnitude, then a zero with the same sign as start is returned. </li> <li>If start is infinite and direction has a value such that the result should have a smaller magnitude, Float.MAX_VALUE with the same sign as start is returned. </li> <li>If start is equal to ± Float.MAX_VALUE and direction has a value such that the result should have a larger magnitude, an infinity with same sign as start is returned.</li> </ul> <p>Parameters:</p> <ul> <li>start - starting floating-point value</li> <li>direction - value indicating which of start's neighbors or start should be returned </li> </ul> <p>Returns:</p> <ul> <li>The floating-point number adjacent to start in the direction of direction.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload