rint

Rounds x to the nearest integer value, using the current rounding mode.

If the return value is not equal to x, the FE_INEXACT exception is raised.

nearbyint performs the same operation, but does not set the FE_INEXACT exception.

  1. real rint(real x)
  2. double rint(double x)
  3. float rint(float x)
    pragma(inline, true) @safe pure nothrow @nogc
    float
    rint
    (
    float x
    )

Examples

import std.math.traits : isNaN;

version (IeeeFlagsSupport) resetIeeeFlags();
assert(rint(0.4) == 0);
version (IeeeFlagsSupport) assert(ieeeFlags.inexact);

assert(rint(0.5) == 0);
assert(rint(0.6) == 1);
assert(rint(100.0) == 100);

assert(isNaN(rint(real.nan)));
assert(rint(real.infinity) == real.infinity);
assert(rint(-real.infinity) == -real.infinity);

Meta