use super::funejson::Value; use super::math_basis_points_convert_rate::convert_rate; /// Integer basis points as the shortest exact decimal in another unit. /// /// # Panics /// Panics if `basis_points` is beyond ±(2^53 - 1) or the unit is unknown. pub fn from_basis_points(basis_points: i64, unit: &str) -> String { // i64 could go further, but TypeScript cannot, and the three languages // must give the same answer or the same error. if !(-9_007_199_254_740_991..=9_007_199_254_740_991).contains(&basis_points) { panic!("basisPoints is outside the safe integer range (±9007199254740991)"); } convert_rate(&basis_points.to_string(), "basis-points", unit) } pub fn fune_vector(args: &[Value]) -> Value { // Refuse what the typed signature cannot hold, with the wording TypeScript // and Python use, rather than let the conversion quietly truncate it. if let Value::Float(f) = args[0] { if f.fract() != 0.0 { panic!("basisPoints must be an integer, received {}", f); } } Value::Str(from_basis_points(args[0].as_i64(), args[1].as_str())) }