pub fn doubling_time(rate: f64) -> FinanceResult<f64>Expand description
Exact periods to double under discrete compounding: ln(2) / ln(1 + rate).
§Errors
FinanceError::InvalidRate if rate <= 0, or non-finite / unsolvable rates.
§Examples
use finance_solution::{doubling_time, rule_of_72, FinanceError};
let exact = doubling_time(0.08).unwrap();
let approx = rule_of_72(0.08).unwrap();
assert!((exact - approx).abs() < 0.5);
assert!((exact - 9.0065).abs() < 1e-3);
match doubling_time(-0.05) {
Err(FinanceError::InvalidRate { rate }) => assert!(rate < 0.0),
other => panic!("expected InvalidRate, got {other:?}"),
}