summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Wilson <jo.alex.w@gmail.com>2023-10-19 21:12:28 +1300
committerGitHub <noreply@github.com>2023-10-19 10:12:28 +0200
commit06ba535c45ae77529dd6d4b5fda69cd4f1836953 (patch)
tree85c8923fa9566b16561de52ab357c757ca937bc9
parent01b14ff316caadb2b3e672f6c2b4f866b8d8b3fe (diff)
Clarified docs for `calc.perm,rem,quo` (#2408)
-rw-r--r--crates/typst-library/src/compute/calc.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/typst-library/src/compute/calc.rs b/crates/typst-library/src/compute/calc.rs
index 9043e1f1..8a7c23ea 100644
--- a/crates/typst-library/src/compute/calc.rs
+++ b/crates/typst-library/src/compute/calc.rs
@@ -445,8 +445,12 @@ pub fn fact(
/// Calculates a permutation.
///
+/// Returns the `k`-permutation of `n`, or the number of ways to choose `k`
+/// items from a set of `n` with regard to order.
+///
/// ```example
-/// #calc.perm(10, 5)
+/// $ "perm"(n, k) &= n!/((n - k)!) \
+/// "perm"(5, 3) &= #calc.perm(5, 3) $
/// ```
#[func(title = "Permutation")]
pub fn perm(
@@ -482,6 +486,9 @@ fn fact_impl(start: u64, end: u64) -> Option<i64> {
/// Calculates a binomial coefficient.
///
+/// Returns the `k`-combination `n`, or the number of ways to choose `k`
+/// items from a set of `n` without regard to order.
+///
/// ```example
/// #calc.binom(10, 5)
/// ```
@@ -779,6 +786,9 @@ pub fn odd(
/// Calculates the remainder of two numbers.
///
+/// The value `calc.rem(x, y)` always has the same sign as `x`, and is smaller
+/// in magnitude than `y`.
+///
/// ```example
/// #calc.rem(20, 6) \
/// #calc.rem(1.75, 0.5)
@@ -796,11 +806,12 @@ pub fn rem(
Ok(dividend.apply2(divisor.v, Rem::rem, Rem::rem))
}
-/// Calculates the quotient of two numbers.
+/// Calculates the quotient (floored division) of two numbers.
///
/// ```example
-/// #calc.quo(14, 5) \
-/// #calc.quo(3.46, 0.5)
+/// $ "quo"(a, b) &= floor(a/b) \
+/// "quo"(14, 5) &= #calc.quo(14, 5) \
+/// "quo"(3.46, 0.5) &= #calc.quo(3.46, 0.5) $
/// ```
#[func(title = "Quotient")]
pub fn quo(