use super::funejson::Value; use super::math_basis_points_convert_rate::convert_rate; /// A rate as whole basis points, the unit the registry keeps rates in. /// Refuses a rate that is not a whole number of basis points (12.345% is /// 1234.5) rather than round it: which way to round a rate is the caller's /// policy, not a conversion's. /// /// # Panics /// Panics if the rate is not a whole number of basis points or is beyond ±(2^53 - 1). pub fn to_basis_points(value: &str, unit: &str) -> i64 { let text = convert_rate(value, unit, "basis-points"); if text.contains('.') { panic!("{} {} is not a whole number of basis points", value, unit); } match text.parse::() { Ok(bp) if (-9_007_199_254_740_991..=9_007_199_254_740_991).contains(&bp) => bp, _ => panic!("{} {} is too large for integer basis points", value, unit), } } pub fn fune_vector(args: &[Value]) -> Value { Value::Int(to_basis_points(args[0].as_str(), args[1].as_str())) }