Trunc v0.1.0

Source
Rounds toward zero.

Package: Math

Signature

func Trunc(x: float64) -> float64;
func Trunc(x: float32) -> float32;

Parameters

NameTypeDescription
xfloat64 / float32The value to round.

Returns

The integer part of x, discarding any fractional part, still represented as a floating-point number. Trunc(-0.4) keeps its sign and is -0.0. Infinities and NaNs pass through unchanged.

Example

import Math::Trunc;

func Main() -> int {
    let a = Trunc(3.9);  // 3.0
    let b = Trunc(-3.9); // -3.0
    return 0;
}

See also

  • Math — the package overview
  • Floor — round down
  • Ceil — round up
  • Round — round to the nearest integer
  • Mod — the remainder built on this truncation