rint

Returns the value of x rounded using the specified rounding _mode. If no rounding _mode is specified the default context rounding _mode is used instead. This function is similar to nearbyint, but if the rounded value is not exact it will throw InexactException

  1. D rint(D x, RoundingMode mode)
  2. D rint(D x)
    @IEEECompliant("roundToIntegralExact", 25)
    D
    rint
    (
    D
    )
    (
    auto const ref D x
    )

Throws

InvalidOperationExceptionx is signaling NaN
InexactExceptionthe result is inexact

Special values

xrint(x)
NaNNaN
±∞±∞
±0.0±0.0

Examples

DecimalControl.resetFlags(ExceptionFlags.inexact);
assert(rint(decimal32("9.9")) == 10);
assert(DecimalControl.inexact);

DecimalControl.resetFlags(ExceptionFlags.inexact);
assert(rint(decimal32("9.0")) == 9);
assert(!DecimalControl.inexact);

Meta