Skip to content

Commit

Permalink
chore: pull across relevant docs from rust definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Apr 19, 2024
1 parent d499897 commit d1fce6b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions noir_stdlib/src/cmp.nr
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,34 @@ impl<A, B, C, D, E> Ord for (A, B, C, D, E) where A: Ord, B: Ord, C: Ord, D: Ord
}
}

/// Compares and returns the maximum of two values.
///
/// Returns the second argument if the comparison determines them to be equal.
///
/// # Examples
///
/// ```
/// use std::cmp;
///
/// assert_eq(cmp::max(1, 2), 2);
/// assert_eq(cmp::max(2, 2), 2);
/// ```
pub fn max<T>(v1: T, v2: T) -> T where T: Ord {
if v1 > v2 { v1 } else { v2 }
}

// Compares and returns the minimum of two values.
//
// Returns the first argument if the comparison determines them to be equal.
//
// # Examples
//
// ```
// use std::cmp;
//
// assert_eq(cmp::min(1, 2), 1);
// assert_eq(cmp::min(2, 2), 2);
// ```
pub fn min<T>(v1: T, v2: T) -> T where T: Ord {
if v1 > v2 { v2 } else { v1 }
}
Expand Down

0 comments on commit d1fce6b

Please sign in to comment.