Packages

A high-performance, extensible expression evaluation engine for Elixir.

Current section

Files

Jump to
excellerate lib excellerate functions math trunc.ex
Raw

lib/excellerate/functions/math/trunc.ex

defmodule ExCellerate.Functions.Math.Trunc do
@moduledoc """
Truncates a number toward zero, removing any fractional part.
Unlike `floor` or `ceil`, `trunc` always drops the decimal portion
regardless of sign.
## Examples
trunc(3.7) → 3
trunc(-3.7) → -3
trunc(5) → 5
"""
@behaviour ExCellerate.Function
import ExCellerate.Functions.Guards
@impl true
def name, do: "trunc"
@impl true
def arity, do: 1
@impl true
def call([n]) do
ensure_number!(n, name())
trunc(n)
end
end