Skip to content

Commit

Permalink
Add trunc(…) function
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jul 24, 2024
1 parent c24e776 commit 1933945
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
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

0 comments on commit 1933945

Please sign in to comment.