The OpenD Programming Language

quantize

Round val to a multiple of pow(base, exp). rfunc specifies the rounding function to use; by default this is rint, which uses the current rounding mode.

  1. Unqual!F quantize(F val, F unit)
  2. Unqual!F quantize(F val, E exp)
    quantize
    (
    real base
    alias rfunc = rint
    F
    E
    )
    (
    const F val
    ,
    const E exp
    )
    if (
    is(typeof(rfunc(F.init)) : F) &&
    &&
    )
  3. Unqual!F quantize(F val)

Examples

import std.math.operations : isClose;

assert(isClose(12345.6789L.quantize!10(-2), 12345.68L));
assert(isClose(12345.6789L.quantize!(10, -2), 12345.68L));
assert(isClose(12345.6789L.quantize!(10, floor)(-2), 12345.67L));
assert(isClose(12345.6789L.quantize!(10, -2, floor), 12345.67L));

assert(isClose(12345.6789L.quantize!22(1), 12342.0L));
assert(isClose(12345.6789L.quantize!22, 12342.0L));

Meta