From 285c2f617b74e182be69decea46bbd0afdb0f604 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Sat, 26 Jun 2021 13:06:37 +0200 Subject: Cleanse library - Remove doc-comments for Typst functions from library - Reduce number of library source files --- src/library/math.rs | 57 ----------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 src/library/math.rs (limited to 'src/library/math.rs') diff --git a/src/library/math.rs b/src/library/math.rs deleted file mode 100644 index 4afb540d..00000000 --- a/src/library/math.rs +++ /dev/null @@ -1,57 +0,0 @@ -use std::cmp::Ordering; - -use super::*; - -/// `min`: The minimum of two values. -/// -/// # Positional parameters -/// - Values: variadic, must be comparable. -/// -/// # Return value -/// The minimum of the sequence of values. For equal elements, the first one is -/// returned. -pub fn min(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - minmax(ctx, args, Ordering::Less) -} - -/// `max`: The maximum of two values. -/// -/// # Positional parameters -/// - Values: variadic, must be comparable. -/// -/// # Return value -/// The maximum of the sequence of values. For equal elements, the first one is -/// returned. -pub fn max(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value { - minmax(ctx, args, Ordering::Greater) -} - -/// Find the minimum or maximum of a sequence of values. -fn minmax(ctx: &mut EvalContext, args: &mut FuncArgs, goal: Ordering) -> Value { - let mut extremum = None; - - while let Some(value) = args.eat::(ctx) { - if let Some(prev) = &extremum { - match value.cmp(&prev) { - Some(ordering) if ordering == goal => extremum = Some(value), - Some(_) => {} - None => { - ctx.diag(error!( - args.span, - "cannot compare {} with {}", - prev.type_name(), - value.type_name(), - )); - return Value::Error; - } - } - } else { - extremum = Some(value); - } - } - - extremum.unwrap_or_else(|| { - args.expect::(ctx, "value"); - Value::Error - }) -} -- cgit v1.2.3