nearbyint

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.

  1. D nearbyint(D x, RoundingMode mode)
    @IEEECompliant("roundToIntegralTiesToAway", 19)
    @IEEECompliant("roundToIntegralTiesToEven", 19)
    @IEEECompliant("roundToIntegralTowardNegative", 19)
    @IEEECompliant("roundToIntegralTowardPositive", 19)
    @IEEECompliant("roundToIntegralTowardZero", 19)
    D
    nearbyint
    (
    D
    )
    (
    auto const ref D x
    ,)
  2. D nearbyint(D x)

Throws

InvalidOperationException if x is signaling NaN

Special values

xnearbyint(x)
NaNNaN
±∞±∞
±0.0±0.0

Examples

assert(nearbyint(decimal32("1.2"), RoundingMode.tiesToEven) == 1);
assert(nearbyint(decimal64("2.7"), RoundingMode.tiesToAway) == 3);
assert(nearbyint(decimal128("-7.9"), RoundingMode.towardZero) == -7);
assert(nearbyint(decimal128("6.66")) == 7);

Meta