Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trunc(…) function #499

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions book/src/list-functions-math.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ More information [here](https://doc.rust-lang.org/std/primitive.f64.html#method.
fn ceil<T: Dim>(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<T: Dim>(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).
Expand Down
5 changes: 5 additions & 0 deletions numbat/modules/core/functions.nbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ fn floor<T: Dim>(x: T) -> T
@url("https://doc.rust-lang.org/std/primitive.f64.html#method.ceil")
fn ceil<T: Dim>(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<T: Dim>(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")
Expand Down
1 change: 1 addition & 0 deletions numbat/src/ffi/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn functions() -> &'static HashMap<String, ForeignFunction> {
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);
Expand Down
1 change: 1 addition & 0 deletions numbat/src/ffi/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading