use super::funejson::Value; use super::money_amount::{assert_same_currency, money_from_value, Money}; /// -1, 0 or 1, comparing two amounts of the same currency. /// /// Refuses mixed currencies: which of GBP 10 and EUR 10 is larger depends on a /// rate, and a comparison that ignores the currency sorts a list into nonsense. /// /// # Panics /// Panics if the two amounts are in different currencies. pub fn compare_money(a: &Money, b: &Money) -> i64 { assert_same_currency(a, b); match a.minor.cmp(&b.minor) { std::cmp::Ordering::Less => -1, std::cmp::Ordering::Equal => 0, std::cmp::Ordering::Greater => 1, } } pub fn fune_vector(args: &[Value]) -> Value { Value::Int(compare_money( &money_from_value(&args[0]), &money_from_value(&args[1]), )) }