From 4e0d5451854d8d3ad199afbb5824bb01d4a6a40e Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 24 Jul 2024 19:23:01 +0200 Subject: [PATCH] =?UTF-8?q?Add=20trunc(=E2=80=A6)=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- book/src/list-functions-math.md | 8 ++++++++ numbat/modules/core/functions.nbt | 5 +++++ numbat/src/ffi/functions.rs | 1 + numbat/src/ffi/math.rs | 1 + 4 files changed, 15 insertions(+) diff --git a/book/src/list-functions-math.md b/book/src/list-functions-math.md index 7b191d90..f39aa5bc 100644 --- a/book/src/list-functions-math.md +++ b/book/src/list-functions-math.md @@ -68,6 +68,14 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method. fn ceil(x: T) -> T ``` +### `trunc` (Truncation) +Returns the integer part of \\( x \\). Non-integer numbers are always truncated towards zero. +More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.trunc). + +```nbt +fn trunc(x: T) -> T +``` + ### `mod` (Modulo) Calculates the least nonnegative remainder of \\( a (\mod b) \\). More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.rem_euclid). diff --git a/numbat/modules/core/functions.nbt b/numbat/modules/core/functions.nbt index 8211bda4..c42b74cf 100644 --- a/numbat/modules/core/functions.nbt +++ b/numbat/modules/core/functions.nbt @@ -36,6 +36,11 @@ fn floor(x: T) -> T @url("https://doc.rust-lang.org/std/primitive.f64.html#method.ceil") fn ceil(x: T) -> T +@name("Truncation") +@description("Returns the integer part of $x$. Non-integer numbers are always truncated towards zero.") +@url("https://doc.rust-lang.org/std/primitive.f64.html#method.trunc") +fn trunc(x: T) -> T + @name("Modulo") @description("Calculates the least nonnegative remainder of $a (\\mod b)$.") @url("https://doc.rust-lang.org/std/primitive.f64.html#method.rem_euclid") diff --git a/numbat/src/ffi/functions.rs b/numbat/src/ffi/functions.rs index 87ea5e6d..f7bae256 100644 --- a/numbat/src/ffi/functions.rs +++ b/numbat/src/ffi/functions.rs @@ -46,6 +46,7 @@ pub(crate) fn functions() -> &'static HashMap { insert_function!(round, 1..=1); insert_function!(floor, 1..=1); insert_function!(ceil, 1..=1); + insert_function!(trunc, 1..=1); insert_function!(sin, 1..=1); insert_function!(cos, 1..=1); diff --git a/numbat/src/ffi/math.rs b/numbat/src/ffi/math.rs index 3fdb23d1..b90e556e 100644 --- a/numbat/src/ffi/math.rs +++ b/numbat/src/ffi/math.rs @@ -41,6 +41,7 @@ simple_polymorphic_math_function!(abs, abs); simple_polymorphic_math_function!(round, round); simple_polymorphic_math_function!(floor, floor); simple_polymorphic_math_function!(ceil, ceil); +simple_polymorphic_math_function!(trunc, trunc); simple_scalar_math_function!(sin, sin); simple_scalar_math_function!(cos, cos);