#[macro_export]
macro_rules! min {
($x: expr) => ($x);
($x: expr, $($xs: expr), +) => {
{
use std::cmp::min;
min($x, min!($($xs), +))
}
}
}
#[macro_export]
macro_rules! max {
($x: expr) => ($x);
($x: expr, $($xs: expr), +) => {
{
use std::cmp::max;
max($x, max!($($xs), +))
}
}
}
#[allow(dead_code)]
pub fn min_f64(x: f64, y: f64) -> f64 {
x.min(y)
}
#[allow(dead_code)]
pub fn max_f64(x: f64, y: f64) -> f64 {
x.max(y)
}
#[macro_export]
macro_rules! min_f {
($x: expr) => ($x as f64);
($x: expr, $($xs: expr), +) => {
{
use min_max_macros::min_f64;
min_f64($x as f64, min_f!($($xs), +))
}
}
}
#[macro_export]
macro_rules! max_f {
($x: expr) => ($x as f64);
($x: expr, $($xs: expr), +) => {
{
use min_max_macros::max_f64;
max_f64($x as f64, max_f!($($xs), +))
}
}
}
#[test]
fn test_min() {
assert!(min!(1) == 1);
assert!(min!(1, 2, 3) == 1);
assert!(min!(-1, 0, 1) == -1);
}
#[test]
fn test_max() {
assert!(max!(1) == 1);
assert!(max!(1, 2, 3) == 3);
assert!(max!(-1, 0, 1) == 1);
}