finance_solution/cashflow/
payment.rs

1//! **Payment calculations.** What is the periodic payment needed for an amortized loan and how much
2//! of that is interest or principal?
3//! 
4//! For most common usages, we recommend the [`payment_solution`](./fn.payment_solution.html) function, which provides a better debugging experience and additional functionality.
5//!
6//! ## Example
7//! ```
8//! let (rate, periods, present_value, future_value, due_at_beginning) = (0.034, 10, 1000, 0, false);
9//! let solution = finance_solution::payment_solution(rate, periods, present_value, future_value, due_at_beginning);
10//! dbg!(&solution);
11//! ```
12//! Outputs to terminal:
13//! ```text
14//! {
15//!     calculated_field: Payment,
16//!     rate: 0.034,
17//!     periods: 10,
18//!     present_value: 1000.0,
19//!     future_value: 0.0,
20//!     due_at_beginning: false,
21//!     payment: -119.63608534268569,
22//!     sum_of_payments: -1196.360853426857,
23//!     sum_of_interest: -196.36085342685692,
24//!     formula: "-119.6361 = ((1000.0000 * 1.034000^10) * -0.034000) / (1.034000^10 - 1)",
25//!     symbolic_formula: "pmt = ((pv * (1 + r)^n) * -r) / ((1 + r)^n - 1)",
26//! }
27//! ```
28//! ```
29//! # use finance_solution::*;
30//! # let (rate, periods, present_value, future_value, due_at_beginning) = (0.034, 10, 1000, 0, false);
31//! # let solution = payment_solution(rate, periods, present_value, future_value, due_at_beginning);
32//! dbg!(solution.print_table());
33//! ```
34//! Outputs to terminal:
35//! ```text
36//! period  payments_to_date  payments_remaining  principal  principal_to_date  principal_remaining  interest  interest_to_date  interest_remaining
37//! ------  ----------------  ------------------  ---------  -----------------  -------------------  --------  ----------------  ------------------
38//!     1         -119.6361         -1_076.7248   -85.6361           -85.6361            -914.3639  -34.0000          -34.0000           -162.3609
39//!     2         -239.2722           -957.0887   -88.5477          -174.1838            -825.8162  -31.0884          -65.0884           -131.2725
40//!     3         -358.9083           -837.4526   -91.5583          -265.7421            -734.2579  -28.0778          -93.1661           -103.1947
41//!     4         -478.5443           -717.8165   -94.6713          -360.4134            -639.5866  -24.9648         -118.1309            -78.2300
42//!     5         -598.1804           -598.1804   -97.8901          -458.3036            -541.6964  -21.7459         -139.8768            -56.4840
43//!     6         -717.8165           -478.5443  -101.2184          -559.5220            -440.4780  -18.4177         -158.2945            -38.0663
44//!     7         -837.4526           -358.9083  -104.6598          -664.1818            -335.8182  -14.9763         -173.2708            -23.0901
45//!     8         -957.0887           -239.2722  -108.2183          -772.4001            -227.5999  -11.4178         -184.6886            -11.6723
46//!     9       -1_076.7248           -119.6361  -111.8977          -884.2978            -115.7022   -7.7384         -192.4270             -3.9339
47//!     10      -1_196.3609             -0.0000  -115.7022          -999.0000              -0.0000   -3.9339         -196.3609              0.0000
48//! ```
49//! # Payment Due at the Beginning vs. the End of the Period
50//!
51//! In a typical loan the payment is due at the end of each period. All other factors being equal,
52//! if the payment is instead due at the beginning of the period the payment amount will be slightly
53//! smaller. This is justified because it means the outstanding principal at any point during the
54//! loan will be slightly smaller since it was paid down one period earlier.
55//!
56//! To make this concrete, suppose we have an amortized loan for $100,000 at 12% annual interest for
57//! ten years. We can run an A/B test where scenario A has the payments due at the end of the period
58//! and scenario B has them due at the beginning. We'll look at the details of the first five
59//! periods:
60//! ```text
61//! period  payment_a  payment_b  principal_a  principal_b  princ_remaining_a  princ_remaining_b
62//! ------  ---------  ---------  -----------  -----------  -----------------  -----------------
63//!      1   1,434.71   1,420.50       434.71     1,420.50          99,565.29          98,579.50
64//!      2   1,434.71   1,420.50       439.06       434.71          99,126.23          98,144.79
65//!      3   1,434.71   1,420.50       443.45       439.06          98,682.79          97,705.73
66//!      4   1,434.71   1,420.50       447.88       443.45          98,234.91          97,262.28
67//!      5   1,434.71   1,420.50       452.36       447.88          97,782.54          96,814.40
68//! ```
69//!
70//! For scenario A a payment of $1,434.71 is due at the end of the month and for scenario B a
71//! lower payment of $1,420.50 is due at the beginning of the month. Yet in both scenarios the loan
72//! is fully paid off by the end of the 120<sup>th</sup> period.
73//!
74//! The reason is that the first monthly payment in the second case went entirely to paying down the
75//! principal, and from that point on the principal (the last two columns in this table) was
76//! slightly smaller at every point in time. Thus the amount of each payment that went toward the
77//! interest was smaller and the amount left to go to principal was larger.
78//!
79//! The sum of the payments in the first case (due at the end) is $172,165.14 and the sum of the
80//! payments in the second case is $170,460.53, a difference of $1,704.61. The relationship between
81//! these sums (and the monthly payment amounts) is based on the interest rate. Specifically:
82//!
83//! > <img src="http://i.upmath.me/svg/payment%5C_due%5C_at%5C_beginning(x)%20%3D%20%7Bpayment%5C_due%5C_at%5C_end(x)%20%5Cover%201%20%2B%20rate%7D" />
84//!
85//! and indeed it turns out that:
86//!
87//! > <img src="http://i.upmath.me/svg/170%2C460.53%20%3D%20%7B172%2C165.14%20%5Cover%201.01%7D" />
88//!
89//! which is a relief. By the way, A/B comparisons like the table above are built into the crate.
90//! See [CashflowSolution::print_ab_comparison](././cashflow/struct.CashflowSolution.html#method.print_ab_comparison).
91//!
92//! # Positive and Negative Amounts
93//!
94//! The example above was an amortized loan for $100,000 at 12% annual interest for ten years. Thus
95//! the present value (the original principal of the loan) was $10,000 and the future value (the
96//! amount still owed at the end) was zero. Also the rate was positive. In cases like this if the
97//! present value is entered as a positive number the payment will be negative, and vice versa:
98//! ```
99//! use finance_solution::*;
100//!
101//! let (rate, periods, present_value, due_at_beginning) = (0.01, 120, 100_000, false);
102//!
103//! let pmt_positive_present_value = payment(rate, periods, present_value, 0.0, due_at_beginning);
104//! assert_rounded_2!(-1_434.71, pmt_positive_present_value);
105//!
106//! let pmt_negative_present_value = payment(rate, periods, -present_value, 0.0, due_at_beginning);
107//! assert_rounded_2!(1_434.71, pmt_negative_present_value);
108//! ```
109//! Either way is fine. It depends on whether we're thinking of the payment as a stream of money
110//! being paid out or coming in. In the period-by-period detail the principal and interest (and
111//! remaining principal and interest and so on) for each period will have the same sign as the
112//! payment.
113//!
114//! # Formulas
115//!
116//! ## Present Value but no Future Value
117//!
118//! In the typical case of an amortized loan the present value will be nonzero and the future value
119//! will be zero. This represents the loan being paid off by the end of the last period.
120//!
121//! If the payment is due at the end of the period the calculation is:
122//!
123//! > <img src="http://i.upmath.me/svg/payment%20%3D%20%7B%7Bpresent%5C_value%20%5Ctimes%20%5Cleft(1%2Brate%5Cright)%5E%7Bperiods%7D%20%5Ctimes%20-rate%7D%20%5Cover%20%5Cleft(1%2Brate%5Cright)%5E%7Bperiods%7D%20-%201%7D" />
124//!
125//! or with some of the more commonly used variables:
126//!
127//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7B%7Bpv%20%5Ctimes%20%5Cleft(1%2Br%5Cright)%5En%20%5Ctimes%20-r%7D%20%5Cover%20%5Cleft(1%2Br%5Cright)%5En%20-%201%7D" />
128//!
129//! Often the payment is shown as `A` and the present value is `P` for principal. In this crate we
130//! use the same symbols for present value, rate, etc. across all of the functions.
131//!
132//! If the payment is due at the beginning of the period the only difference is that we have to
133//! divide the above payment by `(1 + rate)`. So the formula is:
134//!
135//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7B%7Bpv%20%5Ctimes%20%5Cleft(1%2Br%5Cright)%5En%20%5Ctimes%20-r%7D%20%5Cover%20%5Cleft%5B%5Cleft(1%2Br%5Cright)%5En%20-%201%5Cright%5D%20%5Ctextcolor%7Bblue%7D%7B%5Ctimes%20%5Cleft(1%2Br)%7D" />
136//!
137//! ## Future Value but no Present Value
138//!
139//! If there's a future value and the present value is zero, and the payment is due at the end of
140//! the period, the formula is:
141//!
142//! > <img src="http://i.upmath.me/svg/payment%20%3D%20%7Bfuture%5C_value%20%5Ctimes%20-rate%20%5Cover%20%7B%5Cleft(1%2Brate%5Cright)%5E%7Bperiods%7D%20-%201%7D" />
143//!
144//! or:
145//!
146//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7Bfv%20%5Ctimes%20-r%20%5Cover%20%5Cleft(1%2Br%5Cright)%5En%20-%201%5Cright%7D" />
147//!
148//! If the payment is due at the beginning of the period it's:
149//!
150//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7Bfv%20%5Ctimes%20-r%20%5Cover%20%5Cleft%5B%5Cleft(1%2Br%5Cright)%5En%20-%201%5Cright%5D%20%5Ctextcolor%7Bblue%7D%7B%5Ctimes%20(1%2Br)%7D%7D" />
151//!
152//! ## Both Present Value and Future Value
153//!
154//! If both present value and future value are nonzero the formula is:
155//!
156//! > <img src="http://i.upmath.me/svg/payment%20%3D%20%7B%5Cleft%5C%7B%5Cleft%5Bpresent%5C_value%20%5Ctimes%20%5Cleft(1%2Brate%5Cright)%5E%7Bperiods%7D%5Cright%5D%2Bfuture%5C_value%5Cright%5C%7D%20%5Ctimes%20-rate%20%5Cover%20%5Cleft(1%2Brate%5Cright)%5E%7Bperiods%7D%20-%201%7D" />
157//!
158//! or:
159//!
160//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7B%5Cleft%5C%7B%5Cleft%5Bpv%20%5Ctimes%20%5Cleft(1%2Br%5Cright)%5En%5Cright%5D%2Bfv%5Cright%5C%7D%20%5Ctimes%20-r%20%5Cover%20%5Cleft(1%2Br%5Cright)%5En%20-%201%7D" />
161//!
162//! If the payment is due at the beginning of the period it's:
163//!
164//! > <img src="http://i.upmath.me/svg/pmt%20%3D%20%7B%5Cleft%5C%7B%5Cleft%5Bpv%20%5Ctimes%20%5Cleft(1%2Br%5Cright)%5En%5Cright%5D%2Bfv%5Cright%5C%7D%20%5Ctimes%20-r%20%5Cover%20%5Cleft%5B%5Cleft(1%2Br%5Cright)%5En%20-%201%5Cright%5D%20%5Ctextcolor%7Bblue%7D%7B%5Ctimes%20(1%2Br)%7D%7D" />
165//!
166
167use log::{warn};
168
169// Import needed for the function references in the Rustdoc comments.
170#[allow(unused_imports)]
171use crate::*;
172use std::ops::Deref;
173
174const RUN_PAYMENT_INVARIANTS: bool = false;
175
176#[derive(Clone, Debug)]
177pub struct PaymentSolution(CashflowSolution);
178
179#[derive(Clone, Debug)]
180pub struct PaymentSeries(CashflowSeries);
181
182impl PaymentSolution {
183    pub(crate) fn new(solution: CashflowSolution) -> Self {
184        Self {
185            0: solution,
186        }
187    }
188    pub fn print_table(&self) {
189        self.series().print_table(true, true)
190    }
191
192    /// Calculates the period-by-period details of a payment calculation including how the payment
193    /// is broken down between principal and interest.
194    ///
195    /// # Examples
196    /// An amortized loan. Uses [`payment`].
197    /// ```
198    /// use finance_solution::*;
199    ///
200    /// let years = 5;
201    ///
202    /// // The annual percentage rate is 15% and the interest will compound monthly.
203    /// let rate = convert_apr_to_epr(0.15, 12);
204    ///
205    /// // Each period will be one month.
206    /// let periods = years * 12;
207    ///
208    /// // The amount of the loan is $20,000.
209    /// let present_value = 20_000;
210    ///
211    /// // The loan will be fully paid off ot the end of the last period.
212    /// let future_value = 0;
213    ///
214    /// // Payments are due at the end of the month.
215    /// let due_at_beginning = false;
216    ///
217    /// // Calculate the payment, creating a struct that contains additional information and the option
218    /// // to generate period-by-period details.
219    /// let solution = payment_solution(rate, periods, present_value, future_value, due_at_beginning);
220    /// dbg!(&solution);
221    ///
222    /// // Calculate the month-by-month details including the principal and interest paid every month.
223    /// let series = solution.series();
224    /// dbg!(&series);
225    ///
226    /// // Confirm that we have one entry for each period.
227    /// assert_eq!(periods as usize, series.len());
228    ///
229    /// // Print the period detail numbers as a formatted table.
230    /// let include_running_totals = true;
231    /// let include_remaining_amounts = true;
232    /// let locale = num_format::Locale::en;
233    /// let precision = 2; // Two decimal places.
234    /// series.print_table_locale(include_running_totals, include_remaining_amounts, &locale, precision);
235    ///
236    /// // As above but print only the last period for every yeor of the loan, that is periods 12, 24,
237    /// // 36, 48, and 60; and use default formatting.
238    /// series
239    ///     .filter(|x| x.period() % 12 == 0)
240    ///     .print_table(include_running_totals, include_remaining_amounts);
241    /// ```
242    pub fn series(&self) -> PaymentSeries {
243        let mut series = vec![];
244        if self.future_value() != 0.0 {
245            return PaymentSeries::new(CashflowSeries::new(series));
246        }
247        let mut payments_to_date = 0.0;
248        let mut principal_to_date = 0.0;
249        let mut interest_to_date = 0.0;
250        for period in 1..=self.periods() {
251            let principal_remaining_at_start_of_period = self.present_value() + principal_to_date;
252            let interest = if self.due_at_beginning() && period == 1 {
253                0.0
254            } else {
255                -principal_remaining_at_start_of_period * self.rate()
256            };
257            let principal = self.payment() - interest;
258            payments_to_date += self.payment();
259            principal_to_date += principal;
260            interest_to_date += interest;
261            let payments_remaining = self.sum_of_payments() - payments_to_date;
262            let principal_remaining = -(self.present_value() + principal_to_date);
263            let interest_remaining = self.sum_of_interest() - interest_to_date;
264            let (formula, symbolic_formula) = if self.due_at_beginning() && period == 1 {
265                ("0".to_string(), "interest = 0".to_string())
266            } else {
267                let formula = format!("{:.4} = -({:.4} * {:.6})", interest, principal_remaining_at_start_of_period, self.rate());
268                let symbolic_formula = "interest = -(principal * rate)".to_string();
269                (formula, symbolic_formula)
270            };
271            let entry = CashflowPeriod::new(period, self.rate(), self.due_at_beginning(), self.payment(), payments_to_date,
272                                               payments_remaining, principal, principal_to_date, principal_remaining, interest,
273                                               interest_to_date, interest_remaining, formula, symbolic_formula);
274            series.push(entry);
275        }
276        let payment_series = PaymentSeries::new(CashflowSeries::new(series));
277        if RUN_PAYMENT_INVARIANTS {
278            payment_series.invariant(self);
279        }
280        payment_series
281    }
282
283    pub fn print_ab_comparison(
284        &self,
285        other: &PaymentSolution,
286        include_running_totals: bool,
287        include_remaining_amounts: bool)
288    {
289        self.print_ab_comparison_locale_opt(other, include_running_totals, include_remaining_amounts, None, None);
290    }
291
292    pub fn print_ab_comparison_locale(
293        &self,
294        other: &PaymentSolution,
295        include_running_totals: bool,
296        include_remaining_amounts: bool,
297        locale: &num_format::Locale,
298        precision: usize)
299    {
300        self.print_ab_comparison_locale_opt(other, include_running_totals, include_remaining_amounts, Some(locale), Some(precision));
301    }
302
303    fn print_ab_comparison_locale_opt(
304        &self,
305        other: &PaymentSolution,
306        include_running_totals: bool,
307        include_remaining_amounts: bool,
308        locale: Option<&num_format::Locale>,
309        precision: Option<usize>)
310    {
311        println!();
312        // print_ab_comparison_values_string("calculated_field", &self.calculated_field().to_string(), &other.calculated_field.to_string());
313        print_ab_comparison_values_rate("rate", self.rate(), other.rate(), locale, precision);
314        print_ab_comparison_values_int("periods", i128::from(self.periods()), i128::from(other.periods()), locale);
315        print_ab_comparison_values_float("present_value", self.present_value(), other.present_value(), locale, precision);
316        print_ab_comparison_values_float("future_value", self.future_value(), other.future_value(), locale, precision);
317        print_ab_comparison_values_bool("due_at_beginning", self.due_at_beginning(), other.due_at_beginning());
318        print_ab_comparison_values_float("payment", self.payment(), other.payment(), locale, precision);
319        print_ab_comparison_values_float("sum_of_payments", self.sum_of_payments(), other.sum_of_payments(), locale, precision);
320        print_ab_comparison_values_float("sum_of_interest", self.sum_of_interest(), other.sum_of_interest(), locale, precision);
321        print_ab_comparison_values_string("formula", &self.formula(), &other.formula());
322        print_ab_comparison_values_string("symbolic_formula", &self.symbolic_formula(), &other.symbolic_formula());
323
324        self.series().print_ab_comparison_locale_opt(&other.series(), include_running_totals, include_remaining_amounts, locale, precision);
325    }
326
327    fn invariant(&self) {
328        let rate = self.rate();
329        let periods = self.periods();
330        let present_value = self.present_value();
331        let future_value = self.future_value();
332        let payment = self.payment();
333        let sum_of_payments = self.sum_of_payments();
334        let sum_of_interest = self.sum_of_interest();
335        let formula = self.formula();
336        let symbolic_formula = self.symbolic_formula();
337        let present_and_future_value= present_value + future_value;
338        assert!(self.calculated_field().is_payment());
339        assert!(rate.is_finite());
340        assert!(present_value.is_finite());
341        assert!(future_value.is_finite());
342        assert!(payment.is_finite());
343        if future_value == 0.0 {
344            if present_value == 0.0 {
345                assert_eq!(0.0, payment);
346            } else if present_value.is_sign_positive() {
347                assert!(payment.is_sign_negative());
348            } else if present_value.is_sign_negative() {
349                assert!(payment.is_sign_positive());
350            }
351        }
352        assert!(sum_of_payments.is_finite());
353        assert_approx_equal!(sum_of_payments, payment * periods as f64);
354        if future_value == 0.0 {
355            assert_same_sign_or_zero!(sum_of_interest, sum_of_payments);
356        }
357        if periods > 0 && rate != 0.0 && future_value == 0.0 && !is_approx_equal!(0.0, present_value) {
358            assert!(sum_of_interest.abs() < sum_of_payments.abs());
359        }
360        assert_approx_equal!(sum_of_interest, sum_of_payments + present_and_future_value);
361        assert!(!formula.is_empty());
362        assert!(!symbolic_formula.is_empty());
363    }
364
365}
366
367impl Deref for PaymentSolution {
368    type Target = CashflowSolution;
369
370    fn deref(&self) -> &Self::Target {
371        &self.0
372    }
373}
374
375impl PaymentSeries {
376    pub(crate) fn new(series: CashflowSeries) -> Self {
377        Self {
378            0: series,
379        }
380    }
381
382    fn invariant(&self, solution: &CashflowSolution) {
383        let periods = solution.periods();
384        if solution.future_value() != 0.0 {
385            assert_eq!(0, self.len());
386        } else {
387            assert_eq!(periods as usize, self.len());
388        }
389        if self.len() == 0 {
390            return;
391        }
392        let rate = solution.rate();
393        let present_value = solution.present_value();
394        let due_at_beginning = solution.due_at_beginning();
395        assert!(solution.calculated_field().is_payment());
396        let payment = solution.payment();
397        let sum_of_payments = solution.sum_of_payments();
398        let sum_of_interest = solution.sum_of_interest();
399        let mut running_sum_of_payments = 0.0;
400        let mut running_sum_of_principal = 0.0;
401        let mut running_sum_of_interest = 0.0;
402        let mut previous_principal: Option<f64> = None;
403        let mut previous_interest: Option<f64> = None;
404        for (index, entry) in self.iter().enumerate() {
405            running_sum_of_payments += entry.payment();
406            running_sum_of_principal += entry.principal();
407            running_sum_of_interest += entry.interest();
408            assert_eq!(rate, entry.rate());
409            assert_eq!(index + 1, entry.period() as usize);
410            assert_eq!(payment, entry.payment());
411            assert_approx_equal!(running_sum_of_payments, entry.payments_to_date());
412            assert_approx_equal!(sum_of_payments - running_sum_of_payments, entry.payments_remaining());
413            if present_value == 0.0 || rate == 0.0 || (due_at_beginning && index == 0) {
414                assert_eq!(payment, entry.principal());
415                assert_eq!(0.0, entry.interest());
416            } else if present_value > 0.0 {
417                assert!(entry.principal() < 0.0);
418                assert!(entry.interest() < 0.0);
419            } else {
420                // if entry.principal() <= 0.0 {
421                //     bg!(&solution, &series[..10]);
422                // }
423                assert!(entry.principal() > 0.0);
424                assert!(entry.interest() > 0.0);
425            }
426            if index > 0 && previous_interest.unwrap() != 0.0 {
427                // Compared to the previous period the principal should be further from zero and the
428                // interest should be further toward zero. There's a special case where payments are due
429                // at the beginning and we're currently on the second entry. In this case the previous
430                // entry will have had zero interest and a principal matching the full payment amount,
431                // so the two assertions below wouldn't make sense.
432                assert!(entry.principal().abs() > previous_principal.unwrap().abs());
433                assert!(entry.interest().abs() < previous_interest.unwrap().abs());
434            }
435            assert_approx_equal!(running_sum_of_principal, entry.principal_to_date());
436            assert_approx_equal!(-present_value - running_sum_of_principal, entry.principal_remaining());
437            assert_approx_equal!(running_sum_of_interest, entry.interest_to_date());
438            assert_approx_equal!(sum_of_interest - running_sum_of_interest, entry.interest_remaining());
439            assert_approx_equal!(payment, entry.principal() + entry.interest());
440            if index == periods as usize - 1 {
441                // This is the entry for the last period.
442                assert_approx_equal!(0.0, entry.payments_remaining());
443                // if !is_approx_equal!(0.0, entry.principal_remaining()) {
444                //     bg!(&solution, &series[..10], &series[250], &series[490..500]);
445                //}
446                assert_approx_equal!(0.0, entry.principal_remaining());
447                assert_approx_equal!(0.0, entry.interest_remaining());
448            }
449            assert!(!entry.formula().is_empty());
450            assert!(!entry.symbolic_formula().is_empty());
451
452            previous_principal = Some(entry.principal());
453            previous_interest = Some(entry.interest());
454        }
455        assert_approx_equal!(running_sum_of_payments, sum_of_payments);
456        assert_approx_equal!(running_sum_of_principal, -present_value);
457        assert_approx_equal!(running_sum_of_interest, sum_of_interest);
458    }
459}
460
461impl Deref for PaymentSeries {
462    type Target = CashflowSeries;
463
464    fn deref(&self) -> &Self::Target {
465        &self.0
466    }
467}
468
469/// Returns the payment needed at the end of every period for an amortized loan.
470///
471/// Related functions:
472/// * To calculate the payment needed at the end of each period and return a struct that shows the
473/// interest, the formula, and optionally the period-by-period values use [`payment_solution`].
474///
475/// In the typical case where there's a present value and the future value is zero, and the payment
476/// is due at the end of the period, the formula is:
477/// > payment = ((present_value * (1 + rate)<sup>periods</sup>) * -rate) / ((1 + rate)<sup>periods</sup> - 1)
478///
479/// or with the more commonly used variables:
480/// > pmt = ((pv * (1 + r)<sup>n</sup>) * -r) / ((1 + r)<sup>n</sup> - 1)
481///
482/// Often the payment is shown as `A` and the present value is `P` for principal.
483///
484/// If there's a future value and the present value is zero, the formula is:
485/// > payment = (future_value * -rate) / ((1 + rate)<sup>periods</sup> - 1)
486///
487/// or:
488/// > pmt = (fv * -r) / ((1 + r)<sup>n</sup> - 1)
489///
490/// If both present value and future value are nonzero the formula is:
491/// > payment = (((present_value * (1 + rate)<sup>periods</sup>) + future_value) * -rate) / ((1 + rate)<sup>periods</sup> - 1)
492///
493/// or:
494/// > pmt = (((pv * (1 + r)<sup>n</sup>) + fv) * -r) / ((1 + r)<sup>n</sup> - 1)
495///
496/// If the payment is due at the beginning of the period, the only difference is that the payment
497/// is divided by (1 + rate). In our formulas this means multiplying the denominator by (1 + rate)
498/// so in the typical case where there's a present value and the future value is zero, the formula
499/// is:
500/// > payment = ((present_value * (1 + rate)<sup>periods</sup>) * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
501///
502/// or with the more commonly used variables:
503/// > pmt = ((pv * (1 + r)<sup>n</sup>) * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))",
504///
505/// This is nearly the same formula as the one for payments due at the end of the period. The
506/// relationship between the two formulas is that:
507/// > payment_due(x) = payment(x) / (1 + rate)
508///
509/// Thus the payment is slightly smaller if it's due at the beginning of the month since the
510/// principal is paid down a bit faster.
511///
512/// If there's a future value and the present value is zero, the formula is:
513/// > payment = (future_value * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
514///
515/// or:
516/// > pmt = (fv * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))
517///
518/// If both present value and future value are nonzero the formula is:
519/// > payment = (((present_value * (1 + rate)<sup>periods</sup>) + future_value) * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
520///
521/// or:
522/// > pmt = (((pv * (1 + r)<sup>n</sup>) + fv) * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))
523///
524/// # Arguments
525/// * `rate` - The interest rate per period, expressed as a floating point number. For instance
526/// 0.01 would mean 1% interest per period. The rate must match the period type. For instance if the
527/// periods are months and we're starting with an annual interest rate, the rate must be divided by
528/// 12 when calling the function as shown in the example below. The rate often appears as `r` or `i`
529/// (interest) in formulas.
530/// * `periods` - The number of periods such as quarters or periods. Often appears as `n` or `t`
531/// where `t` typically implies years.
532/// * `present_value` - In the case of an amortized loan this is the the principal. It may appear as
533/// `pv` in formulas, or `C` for cash flow or `P` for principal. Assuming that the future value is
534/// zero, the payment will be negative if the present value is positive and vice versa.
535/// * `future_value` - The value at the end of the last period. For a typical amortized loan this
536/// will be zero. It appears as `fv` in formulas.
537/// * `due_at_beginning` - True if the payment is due at the beginning of the period. Typically the
538/// payment will be due at the end of the period so this will be false.
539///
540/// # Panics
541/// The call will fail if `rate` is less than -1.0.
542///
543/// # Examples
544/// A simple amortized loan with the payment due at the end of the month.
545/// ```
546/// # use finance_solution::*;
547/// // The loan will be paid off in five years.
548/// let years = 5;
549///
550/// // The interest rate is 10% per year. Each period is one month so we need to divide the rate
551/// // by the number of months in a year.
552/// let rate = 0.10 / 12.0;
553///
554/// // Each period is one month so we need to multiply the
555/// // years by the number of months in a year.
556/// let periods = years * 12;
557///
558/// // The principal is $10,000.
559/// let present_value = 10_000;
560///
561/// // The loan will be fully paid off by the end of the last period.
562/// let future_value = 0;
563///
564/// let due_at_beginning = false;
565///
566/// let pmt = payment(rate, periods, present_value, future_value, due_at_beginning);
567/// dbg!(pmt);
568///
569/// // The payment is $212.47/month. Since the principal/present value was positive the payment is
570/// // negative.
571/// assert_rounded_4(pmt, -212.4704);
572///
573///
574/// // As above except this time the payment is due at the beginning of the month. This will reduce
575/// // the payment slightly.
576/// let due_at_beginning = true;
577/// let pmt = payment(rate, periods, present_value, future_value, due_at_beginning);
578/// dbg!(pmt);
579///
580/// // The payment is $210.7145, shown as negative since the present value was positive. It's
581/// // slightly smaller (that is, closer to zero) than the payment in the case above where the
582/// // payment was due at the end of the month.
583/// assert_rounded_4(pmt, -210.7145);
584///
585/// ```
586pub fn payment<P, F>(rate: f64, periods: u32, present_value: P, future_value: F, due_at_beginning: bool) -> f64
587    where
588        P: Into<f64> + Copy,
589        F: Into<f64> + Copy
590{
591    let present_value = present_value.into();
592    let future_value = future_value.into();
593
594    //bg!(rate, periods, present_value, future_value, due_at_beginning);
595    assert!(rate.is_finite(), "The rate must be finite (not NaN or infinity)");
596    assert!(rate > -1.0, "The rate must be greater than -1.0 (-100%).");
597    if rate > 1.0 {
598        warn!("You provided a periodic rate ({}) greater than 1. Are you sure you expect a {}% return?", rate, rate * 100.0);
599    }
600    assert!(present_value.is_finite(), "The present value must be finite (not NaN or infinity)");
601    assert!(future_value.is_finite(), "The present value must be finite (not NaN or infinity)");
602    assert!(!(periods == 0 && present_value + future_value != 0.0), "There are no periods and the present value + future value is not zero so there is no way to calculate payments.");
603
604    if periods == 0 {
605        assert_approx_equal!(present_value, -future_value);
606        return 0.0;
607    }
608
609    if rate == 0.0 {
610        // There is no interest so the payment is simply the total amount to be paid divided by the
611        // number of periods.
612        return (-present_value - future_value) / periods as f64;
613    }
614
615    let rate_mult = 1.0 + rate;
616    let num= ((present_value * rate_mult.powf(periods as f64)) + future_value) * -rate;
617    //bg!(num);
618    assert!(num.is_finite());
619    let mut denom = (rate_mult).powf(periods as f64) - 1.0;
620    assert!(denom.is_finite());
621    assert!(denom.is_normal());
622    if due_at_beginning {
623        denom *= rate_mult;
624    }
625    //bg!(denom);
626    assert!(denom.is_finite());
627    assert!(denom.is_normal());
628    let payment = num / denom;
629    //bg!(payment);
630    assert!(payment.is_finite());
631
632    payment
633}
634
635/// Calculates the payment needed for each period for an amortized loan and creates a  struct
636/// showing the interest, the formula, and optionally the period-by-period values.
637///
638/// Related functions:
639/// * To calculate the payment as a simple number instead of a struct when the payment is due at the
640/// end of each period use [payment](./fn.payment.html).
641///
642/// In the typical case where there's a present value and the future value is zero, and the payment
643/// is due at the end of the period, the formula is:
644/// > payment = ((present_value * (1 + rate)<sup>periods</sup>) * -rate) / ((1 + rate)<sup>periods</sup> - 1)
645///
646/// or with the more commonly used variables:
647/// > pmt = ((pv * (1 + r)<sup>n</sup>) * -r) / ((1 + r)<sup>n</sup> - 1)
648///
649/// Often the payment is shown as `A` and the present value is `P` for principal.
650///
651/// If there's a future value and the present value is zero, the formula is:
652/// > payment = (future_value * -rate) / ((1 + rate)<sup>periods</sup> - 1)
653///
654/// or:
655/// > pmt = (fv * -r) / ((1 + r)<sup>n</sup> - 1)
656///
657/// If both present value and future value are nonzero the formula is:
658/// > payment = (((present_value * (1 + rate)<sup>periods</sup>) + future_value) * -rate) / ((1 + rate)<sup>periods</sup> - 1)
659///
660/// or:
661/// > pmt = (((pv * (1 + r)<sup>n</sup>) + fv) * -r) / ((1 + r)<sup>n</sup> - 1)
662///
663/// If the payment is due at the beginning of the period, the only difference is that the payment
664/// is divided by (1 + rate). In our formulas this means multiplying the denominator by (1 + rate)
665/// so in the typical case where there's a present value and the future value is zero, the formula
666/// is:
667/// > payment = ((present_value * (1 + rate)<sup>periods</sup>) * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
668///
669/// or with the more commonly used variables:
670/// > pmt = ((pv * (1 + r)<sup>n</sup>) * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))",
671///
672/// This is nearly the same formula as the one for payments due at the end of the period. The
673/// relationship between the two formulas is that:
674/// > payment_due(x) = payment(x) / (1 + rate)
675///
676/// Thus the payment is slightly smaller if it's due at the beginning of the month since the
677/// principal is paid down a bit faster.
678///
679/// If there's a future value and the present value is zero, the formula is:
680/// > payment = (future_value * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
681///
682/// or:
683/// > pmt = (fv * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))
684///
685/// If both present value and future value are nonzero the formula is:
686/// > payment = (((present_value * (1 + rate)<sup>periods</sup>) + future_value) * -rate) / (((1 + rate)<sup>periods</sup> - 1) * (1 + rate))
687///
688/// or:
689/// > pmt = (((pv * (1 + r)<sup>n</sup>) + fv) * -r) / (((1 + r)<sup>n</sup> - 1) * (1 + r))
690///
691/// # Arguments
692/// * `rate` - The interest rate per period, expressed as a floating point number. For instance
693/// 0.01 would mean 1% interest per period. The rate must match the period type. For instance if the
694/// periods are months and we're starting with an annual interest rate, the rate must be divided by
695/// 12 when calling the function as shown in the example below. The rate often appears as `r` or `i`
696/// (interest) in formulas.
697/// * `periods` - The number of periods such as quarters or periods. Often appears as `n` or `t`
698/// where `t` typically implies years.
699/// * `present_value` - In the case of an amortized loan this is the the principal. It may appear as
700/// `pv` in formulas, or `C` for cash flow or `P` for principal. Assuming that the future value is
701/// zero, the payment will be negative if the present value is positive and vice versa.
702/// * `future_value` - The value at the end of the last period. For a typical amortized loan this
703/// will be zero. It appears as `fv` in formulas.
704/// * `due_at_beginning` - True if the payment is due at the beginning of the period. Typically the
705/// payment will be due at the end of the period so this will be false.
706///
707/// # Panics
708/// The call will fail if `rate` is less than -1.0.
709///
710/// # Examples
711/// Calculate the payment for a simple amortized loan with the payment due at the end of the month,
712/// then examine the formulas and the period-by-period details such as the amount of the payment
713/// that goes to principal and interest.
714/// ```
715/// # use finance_solution::*;
716/// // The interest rate is 11.75% per year. Each period is one month so we need to divide the rate
717/// // by the number of months in a year.
718/// let rate = 0.1175 / 12.0;
719///
720/// // The loan will be paid off in 48 months.
721/// let periods = 48;
722///
723/// // The principal is $12,500.50. Here we'll express it as a negative number so that the payment,
724/// // interest, and principal are all positive numbers for simplicity.
725/// let present_value = -12_500.5;
726///
727/// // The loan will be fully paid off by the end of the last period.
728/// let future_value = 0.0;
729///
730/// let due_at_beginning = false;
731///
732/// let solution = payment_solution(rate, periods, present_value, future_value, due_at_beginning);
733/// // Display the inputs, payment amount, formulas, sum of interest, etc.
734/// dbg!(&solution);
735///
736/// // The payment is $327.65/month. Since the principal/present value was negative the payment is
737/// // positive.
738/// assert_rounded_4(solution.payment(), 327.6538);
739///
740/// // The sum of payments is simply the monthly payment times the number of months.
741/// assert_rounded_4(solution.sum_of_payments(), 15_727.3820);
742///
743/// // The sum of interest is the portion of the sum of payments that is over and above the original
744/// // loan amount. Here we add the present value since it has the opposite sign of the payments.
745/// assert_rounded_4(solution.sum_of_interest(), solution.sum_of_payments() + solution.present_value());
746/// assert_rounded_4(solution.sum_of_interest(), 3_226.8820);
747///
748/// // Examine the formulas. Since the future value is zero we expect to see a slightly simplified
749/// // formula.
750/// let formula = solution.formula();
751/// println!();
752/// dbg!(&formula);
753/// assert_eq!(formula, "327.6538 = (-12500.5000 * 1.009792^48 * -0.009792) / (1.009792^48 - 1)");
754/// let symbolic_formula = solution.symbolic_formula();
755/// println!();
756/// dbg!(&symbolic_formula);
757/// assert_eq!(symbolic_formula, "pmt = (pv * (1 + r)^n * -r) / ((1 + r)^n - 1)");
758///
759/// // Calculate the period-by-period values including the amount of the payment that goes toward
760/// // interest and principle as well as the running tally of the remaining amounts.
761/// let series = solution.series();
762/// // Note that all of the period-by-period values are shown as of the end of the period after that
763/// // period's payment has been made.
764/// println!();
765/// dbg!(&series);
766///
767/// // Print the period-by-period values in a table with two decimal places and the numbers aligned,
768/// // with Vietnamese formatting for the thousands and decimal separators. Show all columns
769/// // including running totals and remaining amounts.
770/// let locale = &num_format::Locale::vi;
771/// let include_running_totals = true;
772/// let include_remaining_amounts = true;
773/// println!();
774/// series.print_table_locale(include_running_totals, include_remaining_amounts, &locale, 2);
775///
776/// // Print a table with only the last period of each year, that is all of the periods that can be
777/// // divided by 12. Include the running totals columns but not remaining amounts. Also this time
778/// // use default formatting without specifying the locale or number of decimal places.
779/// let include_running_totals = true;
780/// let include_remaining_amounts = false;
781/// println!();
782/// series
783///     .filter(|entry| entry.period() % 12 == 0)
784///     .print_table(include_running_totals, include_remaining_amounts);
785///
786/// // Print a table starting at the first period where at least 95% of the interest has been paid
787/// // off, and round all dollar amounts to whole numbers by passing zero as the second argument to
788/// // print_table_locale(). Include the remanining amounts columns but not the running totals.
789/// let include_running_totals = false;
790/// let include_remaining_amounts = true;
791/// println!();
792/// series
793///     .filter(|entry| entry.interest_to_date() >= solution.sum_of_interest() * 0.95)
794///     .print_table_locale(include_running_totals, include_remaining_amounts, locale, 0);
795/// ```
796pub fn payment_solution<P, F>(rate: f64, periods: u32, present_value: P, future_value: F, due_at_beginning: bool) -> PaymentSolution
797    where
798        P: Into<f64> + Copy,
799        F: Into<f64> + Copy
800{
801    let present_value = present_value.into();
802    let future_value = future_value.into();
803    let payment = payment(rate, periods, present_value, future_value, due_at_beginning);
804    let (formula, symbolic_formula) = payment_formula(rate, periods, present_value, future_value, due_at_beginning, payment);
805    let solution = PaymentSolution::new(CashflowSolution::new(CashflowVariable::Payment, rate, periods, present_value, future_value, due_at_beginning, payment, &formula, &symbolic_formula));
806    if RUN_PAYMENT_INVARIANTS {
807        solution.invariant();
808    }
809    solution
810}
811
812fn payment_formula(rate: f64, periods: u32, present_value: f64, future_value: f64, due_at_beginning: bool, payment: f64) -> (String, String) {
813    let rate_multiplier = 1.0 + rate;
814    let (mut formula, mut symbolic_formula) = if periods == 0 {
815        (format!("{:.4}", 0.0), "0".to_string())
816    } else if rate == 0.0 {
817        // There is no interest so the payment is simply the total amount to be paid (the difference
818        // between the present and future value) divided by the number of periods. We subtract
819        // present value from future value because if present_value is higher than future value the
820        // payments should be negative.
821        if future_value == 0.0 {
822            (format!("{:.4} / {}", -present_value, periods), "-pv / n".to_string())
823        } else if present_value == 0.0 {
824            (format!("{:.4} / {}", -future_value, periods), "-fv / n".to_string())
825        } else {
826            // We have both a present and future value.
827            let add_future_value = if future_value > 0.0 {
828                format!(" - {:.4}", future_value)
829            } else {
830                format!(" + {:.4}", -future_value)
831            };
832            let formula = format!("({:.4}{}) / {}", -present_value, add_future_value, periods);
833            let symbolic_formula = "(-pv - fv) / n".to_string();
834            (formula, symbolic_formula)
835        }
836    } else {
837        let (formula_num, symbolic_formula_num) = if future_value == 0.0 {
838            // We can slightly simplify the formula by not including the future value term.
839            (format!("({:.4} * {:.6}^{} * {:.6})", present_value, rate_multiplier, periods, -rate), "(pv * (1 + r)^n * -r)".to_string())
840        } else if present_value == 0.0 {
841            // We can simplify the formula by not including the present value term.
842            (format!("({:.4} * {:.6})", future_value, -rate), "(fv * -r)".to_string())
843        } else {
844            // We have both a present and future value.
845            let add_future_value = if future_value > 0.0 {
846                format!(" + {:.4}", future_value)
847            } else {
848                format!(" - {:.4}", 0.0 - future_value)
849            };
850            (format!("((({:.4} * {:.6}^{}){}) * {:.6})", present_value, rate_multiplier, periods, add_future_value, -rate), "(((pv * (1 + r)^n) + fv) * -r)".to_string())
851        };
852        let mut formula_denom = format!("({:.6}^{} - 1)", rate_multiplier, periods);
853        let mut symbolic_formula_denom = "((1 + r)^n - 1)".to_string();
854        if due_at_beginning {
855            formula_denom = format!("({} * {:.6})", formula_denom, rate_multiplier);
856            symbolic_formula_denom = format!("({} * (1 + r))", symbolic_formula_denom);
857        }
858        (format!("{} / {}", formula_num, formula_denom), format!("{} / {}", symbolic_formula_num, symbolic_formula_denom))
859    };
860    formula = format!("{:.4} = {}", payment, formula);
861    symbolic_formula = format!("pmt = {}", symbolic_formula);
862    (formula, symbolic_formula)
863}
864
865/*
866fn check_payment_parameters(rate: f64, periods: u32, present_value: f64, future_value: f64) {
867    assert!(rate.is_finite(), "The rate must be finite (not NaN or infinity)");
868    assert!(rate >= -1.0, "The rate must be greater than or equal to -1.0 because a rate lower than -100% would mean the investment loses more than its full value in a period.");
869    if rate.abs() > 1. {
870        warn!("You provided a periodic rate ({}) greater than 1. Are you sure you expect a {}% return?", rate, rate * 100.0);
871    }
872    assert!(present_value.is_finite(), "The present value must be finite (not NaN or infinity)");
873    assert!(future_value.is_finite(), "The future value must be finite (not NaN or infinity)");
874    assert!(!(present_value == 0.0 && future_value != 0.0), "The present value is zero and the future value is nonzero so there's no way to solve for the payments.");
875    assert!(!(present_value != 0.0 && future_value == 0.0 && rate != -1.0), "The present value is nonzero, the future value is zero, and the rate is not -100% so there's no way to solve for the payments.");
876    assert!(!(present_value < 0.0 && future_value > 0.0), "The present value is negative and the future value is positive so there's no way to solve for the payments.");
877    assert!(!(present_value > 0.0 && future_value < 0.0), "The present value is positive and the future value is negative so there's no way to solve for the payments.");
878    assert!(!(present_value < 0.0 && future_value < present_value && rate <= 0.0), "The present value and future value are both negative, the future value is less than the present value, and the periodic rate is zero or negative. There's no way to solve for the payments.");
879    assert!(!(present_value < 0.0 && future_value > present_value && rate >= 0.0), "The present value and future value are both negative, the future value is greater than the present value, and the periodic rate is zero or positive. There's no way to solve for the payments.");
880    assert!(!(present_value > 0.0 && future_value > present_value && rate <= 0.0), "The present value and future value are both positive, the future value is greater than the present value, and the periodic rate is zero or negative. There's no way to solve for the payments.");
881    assert!(!(present_value > 0.0 && future_value < present_value && rate >= 0.0), "The present value and future value are both positive, the future value is less than the present value, and the periodic rate is zero or positive. There's no way to solve for the payments.");
882}
883*/
884
885#[cfg(test)]
886mod tests {
887    use super::*;
888    // use crate::*;
889
890    #[test]
891    fn test_payment_due_at_end_nominal() {
892        assert_approx_equal!(-11.9636085342686f64, payment(0.034, 10, 100.0, 0.0, false));
893        assert_approx_equal!(-8.22683411973293f64, payment(-0.034, 10, 100.0, 0.0, false));
894        assert_approx_equal!(11.9636085342686f64, payment(0.034, 10, -100.0, 0.0, false));
895        assert_approx_equal!(-100.097751710655f64, payment(1.0, 10, 100.0, 0.0, false));
896        assert_approx_equal!(-150.01573028944f64, payment(1.5, 10, 100.0, 0.0, false));
897        assert_approx_equal!(-10f64, payment(0.0, 10, 100.0, 0.0, false));
898        assert_approx_equal!(-10.00055000825f64, payment(0.00001, 10, 100.0, 0.0, false));
899        assert_approx_equal!(8.22683411973293f64, payment(-0.034, 10, -100.0, 0.0, false));
900        assert_approx_equal!(9.82270640070143f64, payment(0.034, 10, -100.0, 25.0, false));
901        assert_approx_equal!(14.1045106678357f64, payment(0.034, 10, -100.0, -25.0, false));
902        assert_approx_equal!(-10f64, payment(0.0, 10, 100.0, 0.0, false));
903        assert_approx_equal!(-11f64, payment(0.0, 10, 100.0, 10.0, false));
904        assert_approx_equal!(-9f64, payment(0.0, 10, 100.0, -10.0, false));
905        assert_approx_equal!(-1f64, payment(0.0, 10, 10.0, 0.0, false));
906        assert_approx_equal!(-11f64, payment(0.0, 10, 10.0, 100.0, false));
907        assert_approx_equal!(9f64, payment(0.0, 10, 10.0, -100.0, false));
908        assert_approx_equal!(10f64, payment(0.0, 10, -100.0, 0.0, false));
909        assert_approx_equal!(9f64, payment(0.0, 10, -100.0, 10.0, false));
910        assert_approx_equal!(11f64, payment(0.0, 10, -100.0, -10.0, false));
911        assert_approx_equal!(1f64, payment(0.0, 10, -10.0, 0.0, false));
912        assert_approx_equal!(-9f64, payment(0.0, 10, -10.0, 100.0, false));
913        assert_approx_equal!(11f64, payment(0.0, 10, -10.0, -100.0, false));
914    }
915
916    /*
917    #[test]
918    fn test_payment_edge() {
919        // Zero interest.
920        assert_rounded_6!(-10.0, payment(0.0, 10, 100.0, 0.0));
921        // Zero periods but it's OK because the present and future value are equal.
922        assert_rounded_6!(0.0, payment(0.05, 0, 100.0, 100.0));
923    }
924    */
925
926    #[test]
927    fn test_payment_due_at_beginning_nominal() {
928        assert_approx_equal!(-11.5702210196021f64, payment(0.034, 10, 100.0, 0.0, true));
929        assert_approx_equal!(-8.51639142829496f64, payment(-0.034, 10, 100.0, 0.0, true));
930        assert_approx_equal!(-8.51639142829496f64, payment(-0.034, 10, 100.0, 0.0, true));
931        assert_approx_equal!(-50.0488758553275f64, payment(1.0, 10, 100.0, 0.0, true));
932        assert_approx_equal!(-60.0062921157762f64, payment(1.5, 10, 100.0, 0.0, true));
933        assert_approx_equal!(-10f64, payment(0.0, 10, 100.0, 0.0, true));
934        assert_approx_equal!(-10.0004500037499f64, payment(0.00001, 10, 100.0, 0.0, true));
935        assert_approx_equal!(8.51639142829496f64, payment(-0.034, 10, -100.0, 0.0, true));
936        assert_approx_equal!(9.49971605483697f64, payment(0.034, 10, -100.0, 25.0, true));
937        assert_approx_equal!(13.6407259843672f64, payment(0.034, 10, -100.0, -25.0, true));
938        assert_approx_equal!(-10f64, payment(0.0, 10, 100.0, 0.0, true));
939        assert_approx_equal!(-11f64, payment(0.0, 10, 100.0, 10.0, true));
940        assert_approx_equal!(-9f64, payment(0.0, 10, 100.0, -10.0, true));
941        assert_approx_equal!(-1f64, payment(0.0, 10, 10.0, 0.0, true));
942        assert_approx_equal!(-11f64, payment(0.0, 10, 10.0, 100.0, true));
943        assert_approx_equal!(9f64, payment(0.0, 10, 10.0, -100.0, true));
944        assert_approx_equal!(10f64, payment(0.0, 10, -100.0, 0.0, true));
945        assert_approx_equal!(9f64, payment(0.0, 10, -100.0, 10.0, true));
946        assert_approx_equal!(11f64, payment(0.0, 10, -100.0, -10.0, true));
947        assert_approx_equal!(1f64, payment(0.0, 10, -10.0, 0.0, true));
948        assert_approx_equal!(-9f64, payment(0.0, 10, -10.0, 100.0, true));
949        assert_approx_equal!(11f64, payment(0.0, 10, -10.0, -100.0, true));
950    }
951
952    /*
953    #[should_panic]
954    #[test]
955    fn test_future_value_error_rate_low() {
956        future_value(-101.0, 5, 250_000.00);
957    }
958    */
959
960    /*
961    #[test]
962    fn test_combinations() {
963        // let rates = vec![-0.99, -0.5, -0.05, -0.005, 0.0, 0.005, 0.05, 0.5, 1.0, 10.0, 100.0];
964        let rates = vec![0.0, 0.005, 0.05, 0.5, 1.0, 10.0, 100.0];
965        let periods: Vec<u32> = vec![0, 1, 2, 5, 10, 36, 100, 500];
966        let values: Vec<f64> = vec![-1_000_000.0, -1_234.98, -1.0, 0.0, 5.55555, 99_999.99];
967        for rate_one in rates.iter() {
968            for periods_one in periods.iter() {
969                for present_value_one in values.iter() {
970                    for future_value_one in values.iter() {
971                        for due_at_beginning_one in [false, true].iter() {
972                            println!();
973                            dbg!(rate_one, periods_one, present_value_one, future_value_one, due_at_beginning_one);
974                            if !(*periods_one == 0 && *present_value_one + *future_value_one != 0.0) {
975                                let solution = if *due_at_beginning_one {
976                                    payment_solution(*rate_one, *periods_one, *present_value_one, *future_value_one)
977                                } else {
978                                    payment_due_solution(*rate_one, *periods_one, *present_value_one, *future_value_one)
979                                };
980                                let series = solution.series();
981                                //bg!(&solution, &series);
982                                // If we're already calling the invariant functions at the end of
983                                // payment_solution_internal() and payment_series() there's no point in
984                                // running them again.
985                                if !RUN_PAYMENT_INVARIANTS {
986                                    run_payment_invariants(&solution, &series);
987                                }
988                            }
989                        }
990                    }
991                }
992            }
993        }
994    }
995    */
996
997    fn run_payment_invariants(solution: &PaymentSolution, series: &PaymentSeries) {
998        // Display the solution and series only if either one fails its invariant.
999        let result = std::panic::catch_unwind(|| {
1000            solution.invariant();
1001            series.invariant(solution);
1002        });
1003        //bg!(&result);
1004        if result.is_err() {
1005            dbg!(&solution, &series);
1006            solution.invariant();
1007            series.invariant(solution);
1008        }
1009    }
1010
1011    #[test]
1012    fn test_against_excel_ipmt_month_1() {
1013        // Payments at the end of the period.
1014        let solution = payment_solution(0.0056, 12, 20000.0, 0.0, false);
1015        assert_approx_equal!(-1727.95439349254, solution.payment());
1016        let series = solution.series();
1017        assert_approx_equal!(-112.0, series[0].interest());
1018        assert_approx_equal!(-102.950655396442, series[1].interest());
1019        assert_approx_equal!(-93.8506344631036, series[2].interest());
1020        assert_approx_equal!(-84.6996534125387, series[3].interest());
1021        assert_approx_equal!(-75.4974268680907, series[4].interest());
1022        assert_approx_equal!(-66.2436678549938, series[5].interest());
1023        assert_approx_equal!(-56.9380877914235, series[6].interest());
1024        assert_approx_equal!(-47.5803964794972, series[7].interest());
1025        assert_approx_equal!(-38.1703020962241, series[8].interest());
1026        assert_approx_equal!(-28.7075111844048, series[9].interest());
1027        assert_approx_equal!(-19.1917286434792, series[10].interest());
1028        assert_approx_equal!(-9.62265772032443, series[11].interest());
1029    }
1030
1031    #[test]
1032    fn test_against_excel_ipmt_month_2() {
1033        // Payments at the beginning of the period.
1034        let solution = payment_solution(0.0056, 12, 20000.0, 0.0, true);
1035        assert_approx_equal!(-1718.33173577222, solution.payment());
1036        let series = solution.series();
1037        assert_approx_equal!(0.0, series[0].interest());
1038        assert_approx_equal!(-102.377342279676, series[1].interest());
1039        assert_approx_equal!(-93.3279976761173, series[2].interest());
1040        assert_approx_equal!(-84.2279767427791, series[3].interest());
1041        assert_approx_equal!(-75.0769956922143, series[4].interest());
1042        assert_approx_equal!(-65.8747691477663, series[5].interest());
1043        assert_approx_equal!(-56.6210101346693, series[6].interest());
1044        assert_approx_equal!(-47.315430071099, series[7].interest());
1045        assert_approx_equal!(-37.9577387591728, series[8].interest());
1046        assert_approx_equal!(-28.5476443758997, series[9].interest());
1047        assert_approx_equal!(-19.0848534640803, series[10].interest());
1048        assert_approx_equal!(-9.56907092315476, series[11].interest());
1049    }
1050
1051    #[test]
1052    fn test_against_excel_pmt_mod_5() {
1053        assert_approx_equal!(26063.0811111111f64, payment(-0.1, 1, -12345.67, -12345.67, true));
1054        assert_approx_equal!(11111.103f64, payment(-0.1, 1, -12345.67, 0.0, false));
1055        assert_approx_equal!(12208.4958888889f64, payment(-0.1, 1, -12345.67, 123.4567, true));
1056        assert_approx_equal!(234.56773f64, payment(-0.1, 1, -123.4567, -123.4567, false));
1057        assert_approx_equal!(123.4567f64, payment(-0.1, 1, -123.4567, 0.0, true));
1058        assert_approx_equal!(-12234.55897f64, payment(-0.1, 1, -123.4567, 12345.67, false));
1059        assert_approx_equal!(138.408678111111f64, payment(-0.1, 1, -1.234567, -123.4567, true));
1060        assert_approx_equal!(-0.1234567f64, payment(-0.1, 1, -1.234567, 1.234567, false));
1061        assert_approx_equal!(-13716.1765441111f64, payment(-0.1, 1, -1.234567, 12345.67, true));
1062        assert_approx_equal!(1.234567f64, payment(-0.1, 1, 0.0, -1.234567, false));
1063        assert_approx_equal!(-1.37174111111111f64, payment(-0.1, 1, 0.0, 1.234567, true));
1064        assert_approx_equal!(12344.5588897f64, payment(-0.1, 1, 1.234567, -12345.67, false));
1065        assert_approx_equal!(0.137174111111111f64, payment(-0.1, 1, 1.234567, -1.234567, true));
1066        assert_approx_equal!(-124.5678103f64, payment(-0.1, 1, 1.234567, 123.4567, false));
1067        assert_approx_equal!(13593.9544111111f64, payment(-0.1, 1, 123.4567, -12345.67, true));
1068        assert_approx_equal!(-111.11103f64, payment(-0.1, 1, 123.4567, 0.0, false));
1069        assert_approx_equal!(-260.630811111111f64, payment(-0.1, 1, 123.4567, 123.4567, true));
1070        assert_approx_equal!(-10987.6463f64, payment(-0.1, 1, 12345.67, -123.4567, false));
1071        assert_approx_equal!(-12345.67f64, payment(-0.1, 1, 12345.67, 0.0, true));
1072        assert_approx_equal!(-23456.773f64, payment(-0.1, 1, 12345.67, 12345.67, false));
1073        assert_approx_equal!(5920.14584795322f64, payment(-0.1, 2, -12345.67, -123.4567, true));
1074        assert_approx_equal!(5262.50428052632f64, payment(-0.1, 2, -12345.67, 1.234567, false));
1075        assert_approx_equal!(-1371.74111111111f64, payment(-0.1, 2, -12345.67, 12345.67, true));
1076        assert_approx_equal!(53.2813126315789f64, payment(-0.1, 2, -123.4567, -1.234567, false));
1077        assert_approx_equal!(57.7575204678363f64, payment(-0.1, 2, -123.4567, 1.234567, true));
1078        assert_approx_equal!(6498.24736803684f64, payment(-0.1, 2, -1.234567, -12345.67, false));
1079        assert_approx_equal!(1.3067639005848f64, payment(-0.1, 2, -1.234567, -1.234567, true));
1080        assert_approx_equal!(-64.4508951210526f64, payment(-0.1, 2, -1.234567, 123.4567, false));
1081        assert_approx_equal!(7219.69005847953f64, payment(-0.1, 2, 0.0, -12345.67, true));
1082        assert_approx_equal!(0f64, payment(-0.1, 2, 0.0, 0.0, false));
1083        assert_approx_equal!(-72.1969005847953f64, payment(-0.1, 2, 0.0, 123.4567, true));
1084        assert_approx_equal!(64.4508951210526f64, payment(-0.1, 2, 1.234567, -123.4567, false));
1085        assert_approx_equal!(-0.584794894736842f64, payment(-0.1, 2, 1.234567, 0.0, true));
1086        assert_approx_equal!(-6498.24736803684f64, payment(-0.1, 2, 1.234567, 12345.67, false));
1087        assert_approx_equal!(13.7174111111111f64, payment(-0.1, 2, 123.4567, -123.4567, true));
1088        assert_approx_equal!(-53.2813126315789f64, payment(-0.1, 2, 123.4567, 1.234567, false));
1089        assert_approx_equal!(-7278.16954795322f64, payment(-0.1, 2, 123.4567, 12345.67, true));
1090        assert_approx_equal!(-5262.50428052632f64, payment(-0.1, 2, 12345.67, -1.234567, false));
1091        assert_approx_equal!(-5848.67091637427f64, payment(-0.1, 2, 12345.67, 1.234567, true));
1092        assert_approx_equal!(4794.91701748431f64, payment(-0.1, 5, -12345.67, -12345.67, false));
1093        assert_approx_equal!(1978.30720327003f64, payment(-0.1, 5, -12345.67, -1.234567, true));
1094        assert_approx_equal!(1750.02758865473f64, payment(-0.1, 5, -12345.67, 123.4567, false));
1095        assert_approx_equal!(3369.4930653662f64, payment(-0.1, 5, -123.4567, -12345.67, true));
1096        assert_approx_equal!(17.8017500874216f64, payment(-0.1, 5, -123.4567, 0.0, false));
1097        assert_approx_equal!(-13.7174111111111f64, payment(-0.1, 5, -123.4567, 123.4567, true));
1098        assert_approx_equal!(30.3254375882958f64, payment(-0.1, 5, -1.234567, -123.4567, false));
1099        assert_approx_equal!(0.197797223193573f64, payment(-0.1, 5, -1.234567, 0.0, true));
1100        assert_approx_equal!(-3014.56399124128f64, payment(-0.1, 5, -1.234567, 12345.67, false));
1101        assert_approx_equal!(33.4971334304684f64, payment(-0.1, 5, 0.0, -123.4567, true));
1102        assert_approx_equal!(-0.301474200874216f64, payment(-0.1, 5, 0.0, 1.234567, false));
1103        assert_approx_equal!(-3349.71334304684f64, payment(-0.1, 5, 0.0, 12345.67, true));
1104        assert_approx_equal!(0.1234567f64, payment(-0.1, 5, 1.234567, -1.234567, false));
1105        assert_approx_equal!(-0.532768557498257f64, payment(-0.1, 5, 1.234567, 1.234567, true));
1106        assert_approx_equal!(2996.94025865473f64, payment(-0.1, 5, 123.4567, -12345.67, false));
1107        assert_approx_equal!(-19.4447509850526f64, payment(-0.1, 5, 123.4567, -1.234567, true));
1108        assert_approx_equal!(-47.9491701748431f64, payment(-0.1, 5, 123.4567, 123.4567, false));
1109        assert_approx_equal!(1371.74111111111f64, payment(-0.1, 5, 12345.67, -12345.67, true));
1110        assert_approx_equal!(-1780.17500874216f64, payment(-0.1, 5, 12345.67, 0.0, false));
1111        assert_approx_equal!(-2011.4693653662f64, payment(-0.1, 5, 12345.67, 123.4567, true));
1112        assert_approx_equal!(679.867814949844f64, payment(-0.1, 10, -12345.67, -123.4567, false));
1113        assert_approx_equal!(734.34779422425f64, payment(-0.1, 10, -12345.67, 0.0, true));
1114        assert_approx_equal!(-1234.567f64, payment(-0.1, 10, -12345.67, 12345.67, false));
1115        assert_approx_equal!(28.4043669955961f64, payment(-0.1, 10, -123.4567, -123.4567, true));
1116        assert_approx_equal!(6.41958214653807f64, payment(-0.1, 10, -123.4567, 1.234567, false));
1117        assert_approx_equal!(-2098.74542739312f64, payment(-0.1, 10, -123.4567, 12345.67, true));
1118        assert_approx_equal!(0.255639302960365f64, payment(-0.1, 10, -1.234567, -1.234567, false));
1119        assert_approx_equal!(-0.137174111111111f64, payment(-0.1, 10, -1.234567, 1.234567, true));
1120        assert_approx_equal!(1895.48001480183f64, payment(-0.1, 10, 0.0, -12345.67, false));
1121        assert_approx_equal!(0.210608890533536f64, payment(-0.1, 10, 0.0, -1.234567, true));
1122        assert_approx_equal!(-18.9548001480183f64, payment(-0.1, 10, 0.0, 123.4567, false));
1123        assert_approx_equal!(2106.01547055594f64, payment(-0.1, 10, 1.234567, -12345.67, true));
1124        assert_approx_equal!(-0.0660913014801825f64, payment(-0.1, 10, 1.234567, 0.0, false));
1125        assert_approx_equal!(-21.134323832776f64, payment(-0.1, 10, 1.234567, 123.4567, true));
1126        assert_approx_equal!(12.34567f64, payment(-0.1, 10, 123.4567, -123.4567, false));
1127        assert_approx_equal!(-7.3434779422425f64, payment(-0.1, 10, 123.4567, 0.0, true));
1128        assert_approx_equal!(-1902.08914494984f64, payment(-0.1, 10, 123.4567, 12345.67, false));
1129        assert_approx_equal!(-713.286905170897f64, payment(-0.1, 10, 12345.67, -123.4567, true));
1130        assert_approx_equal!(-661.102562803305f64, payment(-0.1, 10, 12345.67, 1.234567, false));
1131        assert_approx_equal!(-2840.43669955961f64, payment(-0.1, 10, 12345.67, 12345.67, true));
1132        assert_approx_equal!(6.51973876437762f64, payment(-0.1, 50, -12345.67, -1.234567, false));
1133        assert_approx_equal!(6.96838470653066f64, payment(-0.1, 50, -12345.67, 1.234567, true));
1134        assert_approx_equal!(1241.02659892513f64, payment(-0.1, 50, -123.4567, -12345.67, false));
1135        assert_approx_equal!(0.208947432501432f64, payment(-0.1, 50, -123.4567, -1.234567, true));
1136        assert_approx_equal!(-12.34567f64, payment(-0.1, 50, -123.4567, 123.4567, false));
1137        assert_approx_equal!(1378.84809118264f64, payment(-0.1, 50, -1.234567, -12345.67, true));
1138        assert_approx_equal!(0.000639564250012761f64, payment(-0.1, 50, -1.234567, 0.0, false));
1139        assert_approx_equal!(-13.7877631786125f64, payment(-0.1, 50, -1.234567, 123.4567, true));
1140        assert_approx_equal!(12.4096264250013f64, payment(-0.1, 50, 0.0, -123.4567, false));
1141        assert_approx_equal!(0f64, payment(-0.1, 50, 0.0, 0.0, true));
1142        assert_approx_equal!(-1240.96264250013f64, payment(-0.1, 50, 0.0, 12345.67, false));
1143        assert_approx_equal!(13.7877631786125f64, payment(-0.1, 50, 1.234567, -123.4567, true));
1144        assert_approx_equal!(-0.124735828500026f64, payment(-0.1, 50, 1.234567, 1.234567, false));
1145        assert_approx_equal!(-1378.84809118264f64, payment(-0.1, 50, 1.234567, 12345.67, true));
1146        assert_approx_equal!(0.0601398392487366f64, payment(-0.1, 50, 123.4567, -1.234567, false));
1147        assert_approx_equal!(-0.208947432501432f64, payment(-0.1, 50, 123.4567, 1.234567, true));
1148        assert_approx_equal!(1234.567f64, payment(-0.1, 50, 12345.67, -12345.67, false));
1149        assert_approx_equal!(-6.96838470653066f64, payment(-0.1, 50, 12345.67, -1.234567, true));
1150        assert_approx_equal!(-18.8052689251289f64, payment(-0.1, 50, 12345.67, 123.4567, false));
1151        assert_approx_equal!(1371.74111112109f64, payment(-0.1, 250, -12345.67, -12345.67, true));
1152        assert_approx_equal!(4.48892163617149E-09f64, payment(-0.1, 250, -12345.67, 0.0, false));
1153        assert_approx_equal!(-13.7174111061733f64, payment(-0.1, 250, -12345.67, 123.4567, true));
1154        assert_approx_equal!(12.3456700000898f64, payment(-0.1, 250, -123.4567, -123.4567, false));
1155        assert_approx_equal!(4.98769070685721E-11f64, payment(-0.1, 250, -123.4567, 0.0, true));
1156        assert_approx_equal!(-1234.56700000444f64, payment(-0.1, 250, -123.4567, 12345.67, false));
1157        assert_approx_equal!(13.7174111111615f64, payment(-0.1, 250, -1.234567, -123.4567, true));
1158        assert_approx_equal!(-0.1234567f64, payment(-0.1, 250, -1.234567, 1.234567, false));
1159        assert_approx_equal!(-1371.7411111161f64, payment(-0.1, 250, -1.234567, 12345.67, true));
1160        assert_approx_equal!(0.123456700000449f64, payment(-0.1, 250, 0.0, -1.234567, false));
1161        assert_approx_equal!(-0.13717411111161f64, payment(-0.1, 250, 0.0, 1.234567, true));
1162        assert_approx_equal!(1234.56700000449f64, payment(-0.1, 250, 1.234567, -12345.67, false));
1163        assert_approx_equal!(0.137174111111111f64, payment(-0.1, 250, 1.234567, -1.234567, true));
1164        assert_approx_equal!(-12.3456700000453f64, payment(-0.1, 250, 1.234567, 123.4567, false));
1165        assert_approx_equal!(1371.74111111605f64, payment(-0.1, 250, 123.4567, -12345.67, true));
1166        assert_approx_equal!(-4.48892163617149E-11f64, payment(-0.1, 250, 123.4567, 0.0, false));
1167        assert_approx_equal!(-13.7174111112109f64, payment(-0.1, 250, 123.4567, 123.4567, true));
1168        assert_approx_equal!(12.345669995556f64, payment(-0.1, 250, 12345.67, -123.4567, false));
1169        assert_approx_equal!(-4.98769070685721E-09f64, payment(-0.1, 250, 12345.67, 0.0, true));
1170        assert_approx_equal!(-1234.56700000898f64, payment(-0.1, 250, 12345.67, 12345.67, false));
1171        assert_approx_equal!(12223.447867f64, payment(-0.01, 1, -12345.67, -1.234567, false));
1172        assert_approx_equal!(12344.4229626263f64, payment(-0.01, 1, -12345.67, 1.234567, true));
1173        assert_approx_equal!(12467.892133f64, payment(-0.01, 1, -123.4567, -12345.67, false));
1174        assert_approx_equal!(124.703737373737f64, payment(-0.01, 1, -123.4567, -1.234567, true));
1175        assert_approx_equal!(-1.234567f64, payment(-0.01, 1, -123.4567, 123.4567, false));
1176        assert_approx_equal!(12471.6083043737f64, payment(-0.01, 1, -1.234567, -12345.67, true));
1177        assert_approx_equal!(1.22222133f64, payment(-0.01, 1, -1.234567, 0.0, false));
1178        assert_approx_equal!(-123.469170373737f64, payment(-0.01, 1, -1.234567, 123.4567, true));
1179        assert_approx_equal!(123.4567f64, payment(-0.01, 1, 0.0, -123.4567, false));
1180        assert_approx_equal!(0f64, payment(-0.01, 1, 0.0, 0.0, true));
1181        assert_approx_equal!(-12345.67f64, payment(-0.01, 1, 0.0, 12345.67, false));
1182        assert_approx_equal!(123.469170373737f64, payment(-0.01, 1, 1.234567, -123.4567, true));
1183        assert_approx_equal!(-2.45678833f64, payment(-0.01, 1, 1.234567, 1.234567, false));
1184        assert_approx_equal!(-12471.6083043737f64, payment(-0.01, 1, 1.234567, 12345.67, true));
1185        assert_approx_equal!(-120.987566f64, payment(-0.01, 1, 123.4567, -1.234567, false));
1186        assert_approx_equal!(-124.703737373737f64, payment(-0.01, 1, 123.4567, 1.234567, true));
1187        assert_approx_equal!(123.4567f64, payment(-0.01, 1, 12345.67, -12345.67, false));
1188        assert_approx_equal!(-12344.4229626263f64, payment(-0.01, 1, 12345.67, -1.234567, true));
1189        assert_approx_equal!(-12345.67f64, payment(-0.01, 1, 12345.67, 123.4567, false));
1190        assert_approx_equal!(12408.3351946602f64, payment(-0.01, 2, -12345.67, -12345.67, true));
1191        assert_approx_equal!(6080.39757135678f64, payment(-0.01, 2, -12345.67, 0.0, false));
1192        assert_approx_equal!(6079.15053398305f64, payment(-0.01, 2, -12345.67, 123.4567, true));
1193        assert_approx_equal!(122.842518427136f64, payment(-0.01, 2, -123.4567, -123.4567, false));
1194        assert_approx_equal!(61.4181572864322f64, payment(-0.01, 2, -123.4567, 0.0, true));
1195        assert_approx_equal!(-6143.05029564322f64, payment(-0.01, 2, -123.4567, 12345.67, false));
1196        assert_approx_equal!(63.2793762330339f64, payment(-0.01, 2, -1.234567, -123.4567, true));
1197        assert_approx_equal!(-0.01234567f64, payment(-0.01, 2, -1.234567, 1.234567, false));
1198        assert_approx_equal!(-6265.90528444409f64, payment(-0.01, 2, -1.234567, 12345.67, true));
1199        assert_approx_equal!(0.620385427135678f64, payment(-0.01, 2, 0.0, -1.234567, false));
1200        assert_approx_equal!(-0.626651946601695f64, payment(-0.01, 2, 0.0, 1.234567, true));
1201        assert_approx_equal!(6203.24623159965f64, payment(-0.01, 2, 1.234567, -12345.67, false));
1202        assert_approx_equal!(0.0124703737373737f64, payment(-0.01, 2, 1.234567, -1.234567, true));
1203        assert_approx_equal!(-62.6465824707035f64, payment(-0.01, 2, 1.234567, 123.4567, false));
1204        assert_approx_equal!(6205.10130873052f64, payment(-0.01, 2, 123.4567, -12345.67, true));
1205        assert_approx_equal!(-60.8039757135678f64, payment(-0.01, 2, 123.4567, 0.0, false));
1206        assert_approx_equal!(-124.083351946602f64, payment(-0.01, 2, 123.4567, 123.4567, true));
1207        assert_approx_equal!(-6018.35902864322f64, payment(-0.01, 2, 12345.67, -123.4567, false));
1208        assert_approx_equal!(-6141.81572864322f64, payment(-0.01, 2, 12345.67, 0.0, true));
1209        assert_approx_equal!(-12284.2518427136f64, payment(-0.01, 2, 12345.67, 12345.67, false));
1210        assert_approx_equal!(2445.19838434817f64, payment(-0.01, 5, -12345.67, -123.4567, true));
1211        assert_approx_equal!(2395.30436949964f64, payment(-0.01, 5, -12345.67, 1.234567, false));
1212        assert_approx_equal!(-124.703737373737f64, payment(-0.01, 5, -12345.67, 12345.67, true));
1213        assert_approx_equal!(24.2074640050469f64, payment(-0.01, 5, -123.4567, -1.234567, false));
1214        assert_approx_equal!(23.9430923342298f64, payment(-0.01, 5, -123.4567, 1.234567, true));
1215        assert_approx_equal!(2519.2525264238f64, payment(-0.01, 5, -1.234567, -12345.67, false));
1216        assert_approx_equal!(0.496421135514489f64, payment(-0.01, 5, -1.234567, -1.234567, true));
1217        assert_approx_equal!(-24.9505740808875f64, payment(-0.01, 5, -1.234567, 123.4567, false));
1218        assert_approx_equal!(2544.45754625931f64, payment(-0.01, 5, 0.0, -12345.67, true));
1219        assert_approx_equal!(0f64, payment(-0.01, 5, 0.0, 0.0, false));
1220        assert_approx_equal!(-25.4445754625931f64, payment(-0.01, 5, 0.0, 123.4567, true));
1221        assert_approx_equal!(24.9505740808875f64, payment(-0.01, 5, 1.234567, -123.4567, false));
1222        assert_approx_equal!(-0.241975380888558f64, payment(-0.01, 5, 1.234567, 0.0, true));
1223        assert_approx_equal!(-2519.2525264238f64, payment(-0.01, 5, 1.234567, 12345.67, false));
1224        assert_approx_equal!(1.24703737373737f64, payment(-0.01, 5, 123.4567, -123.4567, true));
1225        assert_approx_equal!(-24.2074640050469f64, payment(-0.01, 5, 123.4567, 1.234567, false));
1226        assert_approx_equal!(-2568.65508434817f64, payment(-0.01, 5, 123.4567, 12345.67, true));
1227        assert_approx_equal!(-2395.30436949964f64, payment(-0.01, 5, 12345.67, -1.234567, false));
1228        assert_approx_equal!(-2420.0082546402f64, payment(-0.01, 5, 12345.67, 1.234567, true));
1229        assert_approx_equal!(2458.83527112085f64, payment(-0.01, 10, -12345.67, -12345.67, false));
1230        assert_approx_equal!(1179.61454561513f64, payment(-0.01, 10, -12345.67, -1.234567, true));
1231        assert_approx_equal!(1154.77782570482f64, payment(-0.01, 10, -12345.67, 123.4567, false));
1232        assert_approx_equal!(1315.98270547074f64, payment(-0.01, 10, -123.4567, -12345.67, true));
1233        assert_approx_equal!(11.6768928556043f64, payment(-0.01, 10, -123.4567, 0.0, false));
1234        assert_approx_equal!(-1.24703737373737f64, payment(-0.01, 10, -123.4567, 123.4567, true));
1235        assert_approx_equal!(13.0282287841603f64, payment(-0.01, 10, -1.234567, -123.4567, false));
1236        assert_approx_equal!(0.117948412682871f64, payment(-0.01, 10, -1.234567, 0.0, true));
1237        assert_approx_equal!(-1291.02921663187f64, payment(-0.01, 10, -1.234567, 12345.67, false));
1238        assert_approx_equal!(13.0418786420245f64, payment(-0.01, 10, 0.0, -123.4567, true));
1239        assert_approx_equal!(-0.129114598556043f64, payment(-0.01, 10, 0.0, 1.234567, false));
1240        assert_approx_equal!(-1304.18786420245f64, payment(-0.01, 10, 0.0, 12345.67, true));
1241        assert_approx_equal!(0.01234567f64, payment(-0.01, 10, 1.234567, -1.234567, false));
1242        assert_approx_equal!(-0.248367199103116f64, payment(-0.01, 10, 1.234567, 1.234567, true));
1243        assert_approx_equal!(1279.46909270482f64, payment(-0.01, 10, 123.4567, -12345.67, false));
1244        assert_approx_equal!(-11.6644224818669f64, payment(-0.01, 10, 123.4567, -1.234567, true));
1245        assert_approx_equal!(-24.5883527112085f64, payment(-0.01, 10, 123.4567, 123.4567, false));
1246        assert_approx_equal!(124.703737373737f64, payment(-0.01, 10, 12345.67, -12345.67, true));
1247        assert_approx_equal!(-1167.68928556043f64, payment(-0.01, 10, 12345.67, 0.0, false));
1248        assert_approx_equal!(-1192.52600547074f64, payment(-0.01, 10, 12345.67, 123.4567, true));
1249        assert_approx_equal!(192.222242449522f64, payment(-0.01, 50, -12345.67, -123.4567, false));
1250        assert_approx_equal!(191.006776127135f64, payment(-0.01, 50, -12345.67, 0.0, true));
1251        assert_approx_equal!(-123.4567f64, payment(-0.01, 50, -12345.67, 12345.67, false));
1252        assert_approx_equal!(5.06717289628007f64, payment(-0.01, 50, -123.4567, -123.4567, true));
1253        assert_approx_equal!(1.85971174282205f64, payment(-0.01, 50, -123.4567, 1.234567, false));
1254        assert_approx_equal!(-313.800445739601f64, payment(-0.01, 50, -123.4567, 12345.67, true));
1255        assert_approx_equal!(0.0501650116731727f64, payment(-0.01, 50, -1.234567, -1.234567, false));
1256        assert_approx_equal!(-0.0124703737373737f64, payment(-0.01, 50, -1.234567, 1.234567, true));
1257        assert_approx_equal!(312.553408365864f64, payment(-0.01, 50, 0.0, -12345.67, false));
1258        assert_approx_equal!(0.0315710513500872f64, payment(-0.01, 50, 0.0, -1.234567, true));
1259        assert_approx_equal!(-3.12553408365864f64, payment(-0.01, 50, 0.0, 123.4567, false));
1260        assert_approx_equal!(315.69141282326f64, payment(-0.01, 50, 1.234567, -12345.67, true));
1261        assert_approx_equal!(-0.0189096708365864f64, payment(-0.01, 50, 1.234567, 0.0, false));
1262        assert_approx_equal!(-3.17620581262144f64, payment(-0.01, 50, 1.234567, 123.4567, true));
1263        assert_approx_equal!(1.234567f64, payment(-0.01, 50, 123.4567, -123.4567, false));
1264        assert_approx_equal!(-1.91006776127135f64, payment(-0.01, 50, 123.4567, 0.0, true));
1265        assert_approx_equal!(-314.444375449522f64, payment(-0.01, 50, 123.4567, 12345.67, false));
1266        assert_approx_equal!(-187.849670992126f64, payment(-0.01, 50, 12345.67, -123.4567, true));
1267        assert_approx_equal!(-189.1279637067f64, payment(-0.01, 50, 12345.67, 1.234567, false));
1268        assert_approx_equal!(-506.717289628007f64, payment(-0.01, 50, 12345.67, 12345.67, true));
1269        assert_approx_equal!(10.9033738910495f64, payment(-0.01, 250, -12345.67, -1.234567, false));
1270        assert_approx_equal!(10.9863682456607f64, payment(-0.01, 250, -12345.67, 1.234567, true));
1271        assert_approx_equal!(134.455538619398f64, payment(-0.01, 250, -123.4567, -12345.67, false));
1272        assert_approx_equal!(0.123569753731294f64, payment(-0.01, 250, -123.4567, -1.234567, true));
1273        assert_approx_equal!(-1.234567f64, payment(-0.01, 250, -123.4567, 123.4567, false));
1274        assert_approx_equal!(135.704775980858f64, payment(-0.01, 250, -1.234567, -12345.67, true));
1275        assert_approx_equal!(0.00108899392271268f64, payment(-0.01, 250, -1.234567, 0.0, false));
1276        assert_approx_equal!(-1.35593676600864f64, payment(-0.01, 250, -1.234567, 123.4567, true));
1277        assert_approx_equal!(1.34346639227127f64, payment(-0.01, 250, 0.0, -123.4567, false));
1278        assert_approx_equal!(0f64, payment(-0.01, 250, 0.0, 0.0, true));
1279        assert_approx_equal!(-134.346639227127f64, payment(-0.01, 250, 0.0, 12345.67, false));
1280        assert_approx_equal!(1.35593676600864f64, payment(-0.01, 250, 1.234567, -123.4567, true));
1281        assert_approx_equal!(-0.0145236578454254f64, payment(-0.01, 250, 1.234567, 1.234567, false));
1282        assert_approx_equal!(-135.704775980858f64, payment(-0.01, 250, 1.234567, 12345.67, true));
1283        assert_approx_equal!(-0.0954647283485555f64, payment(-0.01, 250, 123.4567, -1.234567, false));
1284        assert_approx_equal!(-0.123569753731294f64, payment(-0.01, 250, 123.4567, 1.234567, true));
1285        assert_approx_equal!(123.4567f64, payment(-0.01, 250, 12345.67, -12345.67, false));
1286        assert_approx_equal!(-10.9863682456607f64, payment(-0.01, 250, 12345.67, -1.234567, true));
1287        assert_approx_equal!(-12.2334056193981f64, payment(-0.01, 250, 12345.67, 123.4567, false));
1288        assert_approx_equal!(12456.78103f64, payment(-0.001, 1, -12345.67, -123.4567, false));
1289        assert_approx_equal!(12345.67f64, payment(-0.001, 1, -12345.67, 0.0, true));
1290        assert_approx_equal!(-12.34567f64, payment(-0.001, 1, -12345.67, 12345.67, false));
1291        assert_approx_equal!(247.03698028028f64, payment(-0.001, 1, -123.4567, -123.4567, true));
1292        assert_approx_equal!(122.0986763f64, payment(-0.001, 1, -123.4567, 1.234567, false));
1293        assert_approx_equal!(-12234.571328028f64, payment(-0.001, 1, -123.4567, 12345.67, true));
1294        assert_approx_equal!(2.467899433f64, payment(-0.001, 1, -1.234567, -1.234567, false));
1295        assert_approx_equal!(-0.0012358028028028f64, payment(-0.001, 1, -1.234567, 1.234567, true));
1296        assert_approx_equal!(12345.67f64, payment(-0.001, 1, 0.0, -12345.67, false));
1297        assert_approx_equal!(1.2358028028028f64, payment(-0.001, 1, 0.0, -1.234567, true));
1298        assert_approx_equal!(-123.4567f64, payment(-0.001, 1, 0.0, 123.4567, false));
1299        assert_approx_equal!(12356.793461028f64, payment(-0.001, 1, 1.234567, -12345.67, true));
1300        assert_approx_equal!(-1.233332433f64, payment(-0.001, 1, 1.234567, 0.0, false));
1301        assert_approx_equal!(-124.81484728028f64, payment(-0.001, 1, 1.234567, 123.4567, true));
1302        assert_approx_equal!(0.1234567f64, payment(-0.001, 1, 123.4567, -123.4567, false));
1303        assert_approx_equal!(-123.4567f64, payment(-0.001, 1, 123.4567, 0.0, true));
1304        assert_approx_equal!(-12469.0032433f64, payment(-0.001, 1, 123.4567, 12345.67, false));
1305        assert_approx_equal!(-12222.0897197197f64, payment(-0.001, 1, 12345.67, -123.4567, true));
1306        assert_approx_equal!(-12334.558897f64, payment(-0.001, 1, 12345.67, 1.234567, false));
1307        assert_approx_equal!(-24703.698028028f64, payment(-0.001, 1, 12345.67, 12345.67, true));
1308        assert_approx_equal!(6164.19488377689f64, payment(-0.001, 2, -12345.67, -1.234567, false));
1309        assert_approx_equal!(6169.12882801261f64, payment(-0.001, 2, -12345.67, 1.234567, true));
1310        assert_approx_equal!(6237.55873439555f64, payment(-0.001, 2, -123.4567, -12345.67, false));
1311        assert_approx_equal!(62.3156808918473f64, payment(-0.001, 2, -123.4567, -1.234567, true));
1312        assert_approx_equal!(-0.1234567f64, payment(-0.001, 2, -123.4567, 123.4567, false));
1313        assert_approx_equal!(6182.72204125114f64, payment(-0.001, 2, -1.234567, -12345.67, true));
1314        assert_approx_equal!(0.616357729148074f64, payment(-0.001, 2, -1.234567, 0.0, false));
1315        assert_approx_equal!(-61.204075961621f64, payment(-0.001, 2, -1.234567, 123.4567, true));
1316        assert_approx_equal!(61.7592296148074f64, payment(-0.001, 2, 0.0, -123.4567, false));
1317        assert_approx_equal!(0f64, payment(-0.001, 2, 0.0, 0.0, true));
1318        assert_approx_equal!(-6175.92296148074f64, payment(-0.001, 2, 0.0, 12345.67, false));
1319        assert_approx_equal!(61.204075961621f64, payment(-0.001, 2, 1.234567, -123.4567, true));
1320        assert_approx_equal!(-1.23395002529615f64, payment(-0.001, 2, 1.234567, 1.234567, false));
1321        assert_approx_equal!(-6182.72204125114f64, payment(-0.001, 2, 1.234567, 12345.67, true));
1322        assert_approx_equal!(-61.0181806186593f64, payment(-0.001, 2, 123.4567, -1.234567, false));
1323        assert_approx_equal!(-62.3156808918473f64, payment(-0.001, 2, 123.4567, 1.234567, true));
1324        assert_approx_equal!(12.34567f64, payment(-0.001, 2, 12345.67, -12345.67, false));
1325        assert_approx_equal!(-6169.12882801261f64, payment(-0.001, 2, 12345.67, -1.234567, true));
1326        assert_approx_equal!(-6225.33652109555f64, payment(-0.001, 2, 12345.67, 123.4567, false));
1327        assert_approx_equal!(4940.74949697025f64, payment(-0.001, 5, -12345.67, -12345.67, true));
1328        assert_approx_equal!(2461.73153873664f64, payment(-0.001, 5, -12345.67, 0.0, false));
1329        assert_approx_equal!(2439.43019684612f64, payment(-0.001, 5, -12345.67, 123.4567, true));
1330        assert_approx_equal!(49.3580874747328f64, payment(-0.001, 5, -123.4567, -123.4567, false));
1331        assert_approx_equal!(24.6419573447111f64, payment(-0.001, 5, -123.4567, 0.0, true));
1332        assert_approx_equal!(-2449.45989334927f64, payment(-0.001, 5, -123.4567, 12345.67, false));
1333        assert_approx_equal!(25.0119571984385f64, payment(-0.001, 5, -1.234567, -123.4567, true));
1334        assert_approx_equal!(-0.001234567f64, payment(-0.001, 5, -1.234567, 1.234567, false));
1335        assert_approx_equal!(-2476.30734292569f64, payment(-0.001, 5, -1.234567, 12345.67, true));
1336        assert_approx_equal!(0.247407720873664f64, payment(-0.001, 5, 0.0, -1.234567, false));
1337        assert_approx_equal!(-0.247655376249914f64, payment(-0.001, 5, 0.0, 1.234567, true));
1338        assert_approx_equal!(2473.83103558276f64, payment(-0.001, 5, 1.234567, -12345.67, false));
1339        assert_approx_equal!(0.0012358028028028f64, payment(-0.001, 5, 1.234567, -1.234567, true));
1340        assert_approx_equal!(-24.98694524124f64, payment(-0.001, 5, 1.234567, 123.4567, false));
1341        assert_approx_equal!(2451.91180515443f64, payment(-0.001, 5, 123.4567, -12345.67, true));
1342        assert_approx_equal!(-24.6173153873664f64, payment(-0.001, 5, 123.4567, 0.0, false));
1343        assert_approx_equal!(-49.4074949697025f64, payment(-0.001, 5, 123.4567, 123.4567, true));
1344        assert_approx_equal!(-2436.99076664927f64, payment(-0.001, 5, 12345.67, -123.4567, false));
1345        assert_approx_equal!(-2464.19573447111f64, payment(-0.001, 5, 12345.67, 0.0, true));
1346        assert_approx_equal!(-4935.80874747328f64, payment(-0.001, 5, 12345.67, 12345.67, false));
1347        assert_approx_equal!(1241.42982900313f64, payment(-0.001, 10, -12345.67, -123.4567, true));
1348        assert_approx_equal!(1227.66305848239f64, payment(-0.001, 10, -12345.67, 1.234567, false));
1349        assert_approx_equal!(-12.358028028028f64, payment(-0.001, 10, -12345.67, 12345.67, true));
1350        assert_approx_equal!(12.4018839917413f64, payment(-0.001, 10, -123.4567, -1.234567, false));
1351        assert_approx_equal!(12.1660234668569f64, payment(-0.001, 10, -123.4567, 1.234567, true));
1352        assert_approx_equal!(1240.25552046374f64, payment(-0.001, 10, -1.234567, -12345.67, false));
1353        assert_approx_equal!(0.247039020371685f64, payment(-0.001, 10, -1.234567, -1.234567, true));
1354        assert_approx_equal!(-12.27854871039f64, payment(-0.001, 10, -1.234567, 123.4567, false));
1355        assert_approx_equal!(1241.37411587244f64, payment(-0.001, 10, 0.0, -12345.67, true));
1356        assert_approx_equal!(0f64, payment(-0.001, 10, 0.0, 0.0, false));
1357        assert_approx_equal!(-12.4137411587244f64, payment(-0.001, 10, 0.0, 123.4567, true));
1358        assert_approx_equal!(12.27854871039f64, payment(-0.001, 10, 1.234567, -123.4567, false));
1359        assert_approx_equal!(-0.122901608784441f64, payment(-0.001, 10, 1.234567, 0.0, true));
1360        assert_approx_equal!(-1240.25552046374f64, payment(-0.001, 10, 1.234567, 12345.67, false));
1361        assert_approx_equal!(0.12358028028028f64, payment(-0.001, 10, 123.4567, -123.4567, true));
1362        assert_approx_equal!(-12.4018839917413f64, payment(-0.001, 10, 123.4567, 1.234567, false));
1363        assert_approx_equal!(-1253.66427675088f64, payment(-0.001, 10, 123.4567, 12345.67, true));
1364        assert_approx_equal!(-1227.66305848239f64, payment(-0.001, 10, 12345.67, -1.234567, false));
1365        assert_approx_equal!(-1229.140225256f64, payment(-0.001, 10, 12345.67, 1.234567, true));
1366        assert_approx_equal!(493.682773192249f64, payment(-0.001, 50, -12345.67, -12345.67, false));
1367        assert_approx_equal!(240.93478780609f64, payment(-0.001, 50, -12345.67, -1.234567, true));
1368        assert_approx_equal!(238.138409380163f64, payment(-0.001, 50, -12345.67, 123.4567, false));
1369        assert_approx_equal!(255.676583695782f64, payment(-0.001, 50, -123.4567, -12345.67, true));
1370        assert_approx_equal!(2.40668551596125f64, payment(-0.001, 50, -123.4567, 0.0, false));
1371        assert_approx_equal!(-0.12358028028028f64, payment(-0.001, 50, -123.4567, 123.4567, true));
1372        assert_approx_equal!(2.55420907112086f64, payment(-0.001, 50, -1.234567, -123.4567, false));
1373        assert_approx_equal!(0.0240909461057182f64, payment(-0.001, 50, -1.234567, 0.0, true));
1374        assert_approx_equal!(-252.990154740965f64, payment(-0.001, 50, -1.234567, 12345.67, false));
1375        assert_approx_equal!(2.5326748908521f64, payment(-0.001, 50, 0.0, -123.4567, true));
1376        assert_approx_equal!(-0.0253014221596125f64, payment(-0.001, 50, 0.0, 1.234567, false));
1377        assert_approx_equal!(-253.26748908521f64, payment(-0.001, 50, 0.0, 12345.67, true));
1378        assert_approx_equal!(0.001234567f64, payment(-0.001, 50, 1.234567, -1.234567, false));
1379        assert_approx_equal!(-0.0494176950142391f64, payment(-0.001, 50, 1.234567, 1.234567, true));
1380        assert_approx_equal!(250.607536080163f64, payment(-0.001, 50, 123.4567, -12345.67, false));
1381        assert_approx_equal!(-2.3837678616633f64, payment(-0.001, 50, 123.4567, -1.234567, true));
1382        assert_approx_equal!(-4.93682773192249f64, payment(-0.001, 50, 123.4567, 123.4567, false));
1383        assert_approx_equal!(12.358028028028f64, payment(-0.001, 50, 12345.67, -12345.67, true));
1384        assert_approx_equal!(-240.668551596125f64, payment(-0.001, 50, 12345.67, 0.0, false));
1385        assert_approx_equal!(-243.442135948034f64, payment(-0.001, 50, 12345.67, 123.4567, true));
1386        assert_approx_equal!(44.0000905837691f64, payment(-0.001, 250, -12345.67, -123.4567, false));
1387        assert_approx_equal!(43.4856974635716f64, payment(-0.001, 250, -12345.67, 0.0, true));
1388        assert_approx_equal!(-12.34567f64, payment(-0.001, 250, -12345.67, 12345.67, false));
1389        assert_approx_equal!(0.993294229551712f64, payment(-0.001, 250, -123.4567, -123.4567, true));
1390        assert_approx_equal!(0.42884332948447f64, payment(-0.001, 250, -123.4567, 1.234567, false));
1391        assert_approx_equal!(-55.4088685169639f64, payment(-0.001, 250, -123.4567, 12345.67, true));
1392        assert_approx_equal!(0.00992300935322161f64, payment(-0.001, 250, -1.234567, -1.234567, false));
1393        assert_approx_equal!(-0.0012358028028028f64, payment(-0.001, 250, -1.234567, 1.234567, true));
1394        assert_approx_equal!(55.787881766108f64, payment(-0.001, 250, 0.0, -12345.67, false));
1395        assert_approx_equal!(0.00558437254915996f64, payment(-0.001, 250, 0.0, -1.234567, true));
1396        assert_approx_equal!(-0.55787881766108f64, payment(-0.001, 250, 0.0, 123.4567, false));
1397        assert_approx_equal!(55.8393769218533f64, payment(-0.001, 250, 1.234567, -12345.67, true));
1398        assert_approx_equal!(-0.0043442211766108f64, payment(-0.001, 250, 1.234567, 0.0, false));
1399        assert_approx_equal!(-0.562785824662353f64, payment(-0.001, 250, 1.234567, 123.4567, true));
1400        assert_approx_equal!(0.1234567f64, payment(-0.001, 250, 123.4567, -123.4567, false));
1401        assert_approx_equal!(-0.434856974635716f64, payment(-0.001, 250, 123.4567, 0.0, true));
1402        assert_approx_equal!(-56.2223038837691f64, payment(-0.001, 250, 123.4567, 12345.67, false));
1403        assert_approx_equal!(-42.9272602086556f64, payment(-0.001, 250, 12345.67, -123.4567, true));
1404        assert_approx_equal!(-43.4477905542846f64, payment(-0.001, 250, 12345.67, 1.234567, false));
1405        assert_approx_equal!(-99.3294229551712f64, payment(-0.001, 250, 12345.67, 12345.67, true));
1406        assert_approx_equal!(24691.34f64, payment(0.0, 1, -12345.67, -12345.67, false));
1407        assert_approx_equal!(12346.904567f64, payment(0.0, 1, -12345.67, -1.234567, true));
1408        assert_approx_equal!(12222.2133f64, payment(0.0, 1, -12345.67, 123.4567, false));
1409        assert_approx_equal!(12469.1267f64, payment(0.0, 1, -123.4567, -12345.67, true));
1410        assert_approx_equal!(123.4567f64, payment(0.0, 1, -123.4567, 0.0, false));
1411        assert_approx_equal!(0f64, payment(0.0, 1, -123.4567, 123.4567, true));
1412        assert_approx_equal!(124.691267f64, payment(0.0, 1, -1.234567, -123.4567, false));
1413        assert_approx_equal!(1.234567f64, payment(0.0, 1, -1.234567, 0.0, true));
1414        assert_approx_equal!(-12344.435433f64, payment(0.0, 1, -1.234567, 12345.67, false));
1415        assert_approx_equal!(123.4567f64, payment(0.0, 1, 0.0, -123.4567, true));
1416        assert_approx_equal!(-1.234567f64, payment(0.0, 1, 0.0, 1.234567, false));
1417        assert_approx_equal!(-12345.67f64, payment(0.0, 1, 0.0, 12345.67, true));
1418        assert_approx_equal!(0f64, payment(0.0, 1, 1.234567, -1.234567, false));
1419        assert_approx_equal!(-2.469134f64, payment(0.0, 1, 1.234567, 1.234567, true));
1420        assert_approx_equal!(12222.2133f64, payment(0.0, 1, 123.4567, -12345.67, false));
1421        assert_approx_equal!(-122.222133f64, payment(0.0, 1, 123.4567, -1.234567, true));
1422        assert_approx_equal!(-246.9134f64, payment(0.0, 1, 123.4567, 123.4567, false));
1423        assert_approx_equal!(0f64, payment(0.0, 1, 12345.67, -12345.67, true));
1424        assert_approx_equal!(-12345.67f64, payment(0.0, 1, 12345.67, 0.0, false));
1425        assert_approx_equal!(-12469.1267f64, payment(0.0, 1, 12345.67, 123.4567, true));
1426        assert_approx_equal!(6234.56335f64, payment(0.0, 2, -12345.67, -123.4567, false));
1427        assert_approx_equal!(6172.835f64, payment(0.0, 2, -12345.67, 0.0, true));
1428        assert_approx_equal!(0f64, payment(0.0, 2, -12345.67, 12345.67, false));
1429        assert_approx_equal!(123.4567f64, payment(0.0, 2, -123.4567, -123.4567, true));
1430        assert_approx_equal!(61.1110665f64, payment(0.0, 2, -123.4567, 1.234567, false));
1431        assert_approx_equal!(-6111.10665f64, payment(0.0, 2, -123.4567, 12345.67, true));
1432        assert_approx_equal!(1.234567f64, payment(0.0, 2, -1.234567, -1.234567, false));
1433        assert_approx_equal!(0f64, payment(0.0, 2, -1.234567, 1.234567, true));
1434        assert_approx_equal!(6172.835f64, payment(0.0, 2, 0.0, -12345.67, false));
1435        assert_approx_equal!(0.6172835f64, payment(0.0, 2, 0.0, -1.234567, true));
1436        assert_approx_equal!(-61.72835f64, payment(0.0, 2, 0.0, 123.4567, false));
1437        assert_approx_equal!(6172.2177165f64, payment(0.0, 2, 1.234567, -12345.67, true));
1438        assert_approx_equal!(-0.6172835f64, payment(0.0, 2, 1.234567, 0.0, false));
1439        assert_approx_equal!(-62.3456335f64, payment(0.0, 2, 1.234567, 123.4567, true));
1440        assert_approx_equal!(0f64, payment(0.0, 2, 123.4567, -123.4567, false));
1441        assert_approx_equal!(-61.72835f64, payment(0.0, 2, 123.4567, 0.0, true));
1442        assert_approx_equal!(-6234.56335f64, payment(0.0, 2, 123.4567, 12345.67, false));
1443        assert_approx_equal!(-6111.10665f64, payment(0.0, 2, 12345.67, -123.4567, true));
1444        assert_approx_equal!(-6173.4522835f64, payment(0.0, 2, 12345.67, 1.234567, false));
1445        assert_approx_equal!(-12345.67f64, payment(0.0, 2, 12345.67, 12345.67, true));
1446        assert_approx_equal!(2469.3809134f64, payment(0.0, 5, -12345.67, -1.234567, false));
1447        assert_approx_equal!(2468.8870866f64, payment(0.0, 5, -12345.67, 1.234567, true));
1448        assert_approx_equal!(2493.82534f64, payment(0.0, 5, -123.4567, -12345.67, false));
1449        assert_approx_equal!(24.9382534f64, payment(0.0, 5, -123.4567, -1.234567, true));
1450        assert_approx_equal!(0f64, payment(0.0, 5, -123.4567, 123.4567, false));
1451        assert_approx_equal!(2469.3809134f64, payment(0.0, 5, -1.234567, -12345.67, true));
1452        assert_approx_equal!(0.2469134f64, payment(0.0, 5, -1.234567, 0.0, false));
1453        assert_approx_equal!(-24.4444266f64, payment(0.0, 5, -1.234567, 123.4567, true));
1454        assert_approx_equal!(24.69134f64, payment(0.0, 5, 0.0, -123.4567, false));
1455        assert_approx_equal!(0f64, payment(0.0, 5, 0.0, 0.0, true));
1456        assert_approx_equal!(-2469.134f64, payment(0.0, 5, 0.0, 12345.67, false));
1457        assert_approx_equal!(24.4444266f64, payment(0.0, 5, 1.234567, -123.4567, true));
1458        assert_approx_equal!(-0.4938268f64, payment(0.0, 5, 1.234567, 1.234567, false));
1459        assert_approx_equal!(-2469.3809134f64, payment(0.0, 5, 1.234567, 12345.67, true));
1460        assert_approx_equal!(-24.4444266f64, payment(0.0, 5, 123.4567, -1.234567, false));
1461        assert_approx_equal!(-24.9382534f64, payment(0.0, 5, 123.4567, 1.234567, true));
1462        assert_approx_equal!(0f64, payment(0.0, 5, 12345.67, -12345.67, false));
1463        assert_approx_equal!(-2468.8870866f64, payment(0.0, 5, 12345.67, -1.234567, true));
1464        assert_approx_equal!(-2493.82534f64, payment(0.0, 5, 12345.67, 123.4567, false));
1465        assert_approx_equal!(2469.134f64, payment(0.0, 10, -12345.67, -12345.67, true));
1466        assert_approx_equal!(1234.567f64, payment(0.0, 10, -12345.67, 0.0, false));
1467        assert_approx_equal!(1222.22133f64, payment(0.0, 10, -12345.67, 123.4567, true));
1468        assert_approx_equal!(24.69134f64, payment(0.0, 10, -123.4567, -123.4567, false));
1469        assert_approx_equal!(12.34567f64, payment(0.0, 10, -123.4567, 0.0, true));
1470        assert_approx_equal!(-1222.22133f64, payment(0.0, 10, -123.4567, 12345.67, false));
1471        assert_approx_equal!(12.4691267f64, payment(0.0, 10, -1.234567, -123.4567, true));
1472        assert_approx_equal!(0f64, payment(0.0, 10, -1.234567, 1.234567, false));
1473        assert_approx_equal!(-1234.4435433f64, payment(0.0, 10, -1.234567, 12345.67, true));
1474        assert_approx_equal!(0.1234567f64, payment(0.0, 10, 0.0, -1.234567, false));
1475        assert_approx_equal!(-0.1234567f64, payment(0.0, 10, 0.0, 1.234567, true));
1476        assert_approx_equal!(1234.4435433f64, payment(0.0, 10, 1.234567, -12345.67, false));
1477        assert_approx_equal!(0f64, payment(0.0, 10, 1.234567, -1.234567, true));
1478        assert_approx_equal!(-12.4691267f64, payment(0.0, 10, 1.234567, 123.4567, false));
1479        assert_approx_equal!(1222.22133f64, payment(0.0, 10, 123.4567, -12345.67, true));
1480        assert_approx_equal!(-12.34567f64, payment(0.0, 10, 123.4567, 0.0, false));
1481        assert_approx_equal!(-24.69134f64, payment(0.0, 10, 123.4567, 123.4567, true));
1482        assert_approx_equal!(-1222.22133f64, payment(0.0, 10, 12345.67, -123.4567, false));
1483        assert_approx_equal!(-1234.567f64, payment(0.0, 10, 12345.67, 0.0, true));
1484        assert_approx_equal!(-2469.134f64, payment(0.0, 10, 12345.67, 12345.67, false));
1485        assert_approx_equal!(249.382534f64, payment(0.0, 50, -12345.67, -123.4567, true));
1486        assert_approx_equal!(246.88870866f64, payment(0.0, 50, -12345.67, 1.234567, false));
1487        assert_approx_equal!(0f64, payment(0.0, 50, -12345.67, 12345.67, true));
1488        assert_approx_equal!(2.49382534f64, payment(0.0, 50, -123.4567, -1.234567, false));
1489        assert_approx_equal!(2.44444266f64, payment(0.0, 50, -123.4567, 1.234567, true));
1490        assert_approx_equal!(246.93809134f64, payment(0.0, 50, -1.234567, -12345.67, false));
1491        assert_approx_equal!(0.04938268f64, payment(0.0, 50, -1.234567, -1.234567, true));
1492        assert_approx_equal!(-2.44444266f64, payment(0.0, 50, -1.234567, 123.4567, false));
1493        assert_approx_equal!(246.9134f64, payment(0.0, 50, 0.0, -12345.67, true));
1494        assert_approx_equal!(0f64, payment(0.0, 50, 0.0, 0.0, false));
1495        assert_approx_equal!(-2.469134f64, payment(0.0, 50, 0.0, 123.4567, true));
1496        assert_approx_equal!(2.44444266f64, payment(0.0, 50, 1.234567, -123.4567, false));
1497        assert_approx_equal!(-0.02469134f64, payment(0.0, 50, 1.234567, 0.0, true));
1498        assert_approx_equal!(-246.93809134f64, payment(0.0, 50, 1.234567, 12345.67, false));
1499        assert_approx_equal!(0f64, payment(0.0, 50, 123.4567, -123.4567, true));
1500        assert_approx_equal!(-2.49382534f64, payment(0.0, 50, 123.4567, 1.234567, false));
1501        assert_approx_equal!(-249.382534f64, payment(0.0, 50, 123.4567, 12345.67, true));
1502        assert_approx_equal!(-246.88870866f64, payment(0.0, 50, 12345.67, -1.234567, false));
1503        assert_approx_equal!(-246.93809134f64, payment(0.0, 50, 12345.67, 1.234567, true));
1504        assert_approx_equal!(98.76536f64, payment(0.0, 250, -12345.67, -12345.67, false));
1505        assert_approx_equal!(49.387618268f64, payment(0.0, 250, -12345.67, -1.234567, true));
1506        assert_approx_equal!(48.8888532f64, payment(0.0, 250, -12345.67, 123.4567, false));
1507        assert_approx_equal!(49.8765068f64, payment(0.0, 250, -123.4567, -12345.67, true));
1508        assert_approx_equal!(0.4938268f64, payment(0.0, 250, -123.4567, 0.0, false));
1509        assert_approx_equal!(0f64, payment(0.0, 250, -123.4567, 123.4567, true));
1510        assert_approx_equal!(0.498765068f64, payment(0.0, 250, -1.234567, -123.4567, false));
1511        assert_approx_equal!(0.004938268f64, payment(0.0, 250, -1.234567, 0.0, true));
1512        assert_approx_equal!(-49.377741732f64, payment(0.0, 250, -1.234567, 12345.67, false));
1513        assert_approx_equal!(0.4938268f64, payment(0.0, 250, 0.0, -123.4567, true));
1514        assert_approx_equal!(-0.004938268f64, payment(0.0, 250, 0.0, 1.234567, false));
1515        assert_approx_equal!(-49.38268f64, payment(0.0, 250, 0.0, 12345.67, true));
1516        assert_approx_equal!(0f64, payment(0.0, 250, 1.234567, -1.234567, false));
1517        assert_approx_equal!(-0.009876536f64, payment(0.0, 250, 1.234567, 1.234567, true));
1518        assert_approx_equal!(48.8888532f64, payment(0.0, 250, 123.4567, -12345.67, false));
1519        assert_approx_equal!(-0.488888532f64, payment(0.0, 250, 123.4567, -1.234567, true));
1520        assert_approx_equal!(-0.9876536f64, payment(0.0, 250, 123.4567, 123.4567, false));
1521        assert_approx_equal!(0f64, payment(0.0, 250, 12345.67, -12345.67, true));
1522        assert_approx_equal!(-49.38268f64, payment(0.0, 250, 12345.67, 0.0, false));
1523        assert_approx_equal!(-49.8765068f64, payment(0.0, 250, 12345.67, 123.4567, true));
1524        assert_approx_equal!(12468.8434011773f64, payment(0.0023, 1, -12345.67, -123.4567, true));
1525        assert_approx_equal!(12372.830474f64, payment(0.0023, 1, -12345.67, 1.234567, false));
1526        assert_approx_equal!(28.3298822707772f64, payment(0.0023, 1, -12345.67, 12345.67, true));
1527        assert_approx_equal!(124.97521741f64, payment(0.0023, 1, -123.4567, -1.234567, false));
1528        assert_approx_equal!(122.224965988227f64, payment(0.0023, 1, -123.4567, 1.234567, true));
1529        assert_approx_equal!(12346.9074065041f64, payment(0.0023, 1, -1.234567, -12345.67, false));
1530        assert_approx_equal!(2.46630101177292f64, payment(0.0023, 1, -1.234567, -1.234567, true));
1531        assert_approx_equal!(-122.2192934959f64, payment(0.0023, 1, -1.234567, 123.4567, false));
1532        assert_approx_equal!(12317.3401177292f64, payment(0.0023, 1, 0.0, -12345.67, true));
1533        assert_approx_equal!(0f64, payment(0.0023, 1, 0.0, 0.0, false));
1534        assert_approx_equal!(-123.173401177292f64, payment(0.0023, 1, 0.0, 123.4567, true));
1535        assert_approx_equal!(122.2192934959f64, payment(0.0023, 1, 1.234567, -123.4567, false));
1536        assert_approx_equal!(-1.234567f64, payment(0.0023, 1, 1.234567, 0.0, true));
1537        assert_approx_equal!(-12346.9074065041f64, payment(0.0023, 1, 1.234567, 12345.67, false));
1538        assert_approx_equal!(-0.283298822707772f64, payment(0.0023, 1, 123.4567, -123.4567, true));
1539        assert_approx_equal!(-124.97521741f64, payment(0.0023, 1, 123.4567, 1.234567, false));
1540        assert_approx_equal!(-12440.7968177292f64, payment(0.0023, 1, 123.4567, 12345.67, true));
1541        assert_approx_equal!(-12372.830474f64, payment(0.0023, 1, 12345.67, -1.234567, false));
1542        assert_approx_equal!(-12346.9017340118f64, payment(0.0023, 1, 12345.67, 1.234567, true));
1543        assert_approx_equal!(12359.8838288939f64, payment(0.0023, 2, -12345.67, -12345.67, false));
1544        assert_approx_equal!(6180.54076562542f64, payment(0.0023, 2, -12345.67, -1.234567, true));
1545        assert_approx_equal!(6132.48199100749f64, payment(0.0023, 2, -12345.67, 123.4567, false));
1546        assert_approx_equal!(6213.39497984279f64, payment(0.0023, 2, -123.4567, -12345.67, true));
1547        assert_approx_equal!(61.9413943494696f64, payment(0.0023, 2, -123.4567, 0.0, false));
1548        assert_approx_equal!(0.283298822707772f64, payment(0.0023, 2, -123.4567, 123.4567, true));
1549        assert_approx_equal!(62.2768578829643f64, payment(0.0023, 2, -1.234567, -123.4567, false));
1550        assert_approx_equal!(0.617992560605304f64, payment(0.0023, 2, -1.234567, 0.0, true));
1551        assert_approx_equal!(-6165.12498000346f64, payment(0.0023, 2, -1.234567, 12345.67, false));
1552        assert_approx_equal!(61.5159572378226f64, payment(0.0023, 2, 0.0, -123.4567, true));
1553        assert_approx_equal!(-0.616574439394696f64, payment(0.0023, 2, 0.0, 1.234567, false));
1554        assert_approx_equal!(-6151.59572378226f64, payment(0.0023, 2, 0.0, 12345.67, true));
1555        assert_approx_equal!(-0.0028395041f64, payment(0.0023, 2, 1.234567, -1.234567, false));
1556        assert_approx_equal!(-1.23315213298353f64, payment(0.0023, 2, 1.234567, 1.234567, true));
1557        assert_approx_equal!(6103.80299959749f64, payment(0.0023, 2, 123.4567, -12345.67, false));
1558        assert_approx_equal!(-61.1840964881522f64, payment(0.0023, 2, 123.4567, -1.234567, true));
1559        assert_approx_equal!(-123.598838288939f64, payment(0.0023, 2, 123.4567, 123.4567, false));
1560        assert_approx_equal!(-28.3298822707772f64, payment(0.0023, 2, 12345.67, -12345.67, true));
1561        assert_approx_equal!(-6194.13943494696f64, payment(0.0023, 2, 12345.67, 0.0, false));
1562        assert_approx_equal!(-6241.44156329086f64, payment(0.0023, 2, 12345.67, 123.4567, true));
1563        assert_approx_equal!(2510.7751387519f64, payment(0.0023, 5, -12345.67, -123.4567, false));
1564        assert_approx_equal!(2480.49198641332f64, payment(0.0023, 5, -12345.67, 0.0, true));
1565        assert_approx_equal!(28.395041f64, payment(0.0023, 5, -12345.67, 12345.67, false));
1566        assert_approx_equal!(49.3265409055587f64, payment(0.0023, 5, -123.4567, -123.4567, true));
1567        assert_approx_equal!(24.6161909721225f64, payment(0.0023, 5, -123.4567, 1.234567, false));
1568        assert_approx_equal!(-2427.35718427841f64, payment(0.0023, 5, -123.4567, 12345.67, true));
1569        assert_approx_equal!(0.494399919496415f64, payment(0.0023, 5, -1.234567, -1.234567, false));
1570        assert_approx_equal!(0.00283298822707772f64, payment(0.0023, 5, -1.234567, 1.234567, true));
1571        assert_approx_equal!(2457.80207698207f64, payment(0.0023, 5, 0.0, -12345.67, false));
1572        assert_approx_equal!(0.245216210414255f64, payment(0.0023, 5, 0.0, -1.234567, true));
1573        assert_approx_equal!(-24.5780207698207f64, payment(0.0023, 5, 0.0, 123.4567, false));
1574        assert_approx_equal!(2451.91405494391f64, payment(0.0023, 5, 1.234567, -12345.67, true));
1575        assert_approx_equal!(-0.248619711798207f64, payment(0.0023, 5, 1.234567, 0.0, false));
1576        assert_approx_equal!(-24.7696702400668f64, payment(0.0023, 5, 1.234567, 123.4567, true));
1577        assert_approx_equal!(-0.28395041f64, payment(0.0023, 5, 123.4567, -123.4567, false));
1578        assert_approx_equal!(-24.8049198641332f64, payment(0.0023, 5, 123.4567, 0.0, true));
1579        assert_approx_equal!(-2482.6640481619f64, payment(0.0023, 5, 123.4567, 12345.67, false));
1580        assert_approx_equal!(-2455.9703653719f64, payment(0.0023, 5, 12345.67, -123.4567, true));
1581        assert_approx_equal!(-2486.44289818977f64, payment(0.0023, 5, 12345.67, 1.234567, false));
1582        assert_approx_equal!(-4932.65409055587f64, payment(0.0023, 5, 12345.67, 12345.67, true));
1583        assert_approx_equal!(1250.36027410036f64, payment(0.0023, 10, -12345.67, -1.234567, false));
1584        assert_approx_equal!(1247.24723684586f64, payment(0.0023, 10, -12345.67, 1.234567, true));
1585        assert_approx_equal!(1234.34542969344f64, payment(0.0023, 10, -123.4567, -12345.67, false));
1586        assert_approx_equal!(12.5955953335671f64, payment(0.0023, 10, -123.4567, -1.234567, true));
1587        assert_approx_equal!(0.28395041f64, payment(0.0023, 10, -123.4567, 123.4567, false));
1588        assert_approx_equal!(1219.16399541501f64, payment(0.0023, 10, -1.234567, -12345.67, true));
1589        assert_approx_equal!(0.125023808979548f64, payment(0.0023, 10, -1.234567, 0.0, false));
1590        assert_approx_equal!(-12.0656556709321f64, payment(0.0023, 10, -1.234567, 123.4567, true));
1591        assert_approx_equal!(12.2184304879548f64, payment(0.0023, 10, 0.0, -123.4567, false));
1592        assert_approx_equal!(0f64, payment(0.0023, 10, 0.0, 0.0, true));
1593        assert_approx_equal!(-1221.84304879548f64, payment(0.0023, 10, 0.0, 12345.67, false));
1594        assert_approx_equal!(12.0656556709321f64, payment(0.0023, 10, 1.234567, -123.4567, true));
1595        assert_approx_equal!(-0.247208113859096f64, payment(0.0023, 10, 1.234567, 1.234567, false));
1596        assert_approx_equal!(-1219.16399541501f64, payment(0.0023, 10, 1.234567, 12345.67, true));
1597        assert_approx_equal!(-12.3801965930753f64, payment(0.0023, 10, 123.4567, -1.234567, false));
1598        assert_approx_equal!(-12.5955953335671f64, payment(0.0023, 10, 123.4567, 1.234567, true));
1599        assert_approx_equal!(-28.395041f64, payment(0.0023, 10, 12345.67, -12345.67, false));
1600        assert_approx_equal!(-1247.24723684586f64, payment(0.0023, 10, 12345.67, -1.234567, true));
1601        assert_approx_equal!(-1262.45652028344f64, payment(0.0023, 10, 12345.67, 123.4567, false));
1602        assert_approx_equal!(493.80223210177f64, payment(0.0023, 50, -12345.67, -12345.67, true));
1603        assert_approx_equal!(261.666509117802f64, payment(0.0023, 50, -12345.67, 0.0, false));
1604        assert_approx_equal!(258.738695437118f64, payment(0.0023, 50, -12345.67, 123.4567, true));
1605        assert_approx_equal!(4.94937977235604f64, payment(0.0023, 50, -123.4567, -123.4567, false));
1606        assert_approx_equal!(2.61066057186273f64, payment(0.0023, 50, -123.4567, 0.0, true));
1607        assert_approx_equal!(-230.654803026624f64, payment(0.0023, 50, -123.4567, 12345.67, false));
1608        assert_approx_equal!(2.35346835487359f64, payment(0.0023, 50, -1.234567, -123.4567, true));
1609        assert_approx_equal!(0.0028395041f64, payment(0.0023, 50, -1.234567, 1.234567, false));
1610        assert_approx_equal!(-232.710068309778f64, payment(0.0023, 50, -1.234567, 12345.67, true));
1611        assert_approx_equal!(0.0233271468117802f64, payment(0.0023, 50, 0.0, -1.234567, false));
1612        assert_approx_equal!(-0.0232736174915496f64, payment(0.0023, 50, 0.0, 1.234567, true));
1613        assert_approx_equal!(233.24530146689f64, payment(0.0023, 50, 1.234567, -12345.67, false));
1614        assert_approx_equal!(-0.00283298822707772f64, payment(0.0023, 50, 1.234567, -1.234567, true));
1615        assert_approx_equal!(-2.3588813320898f64, payment(0.0023, 50, 1.234567, 123.4567, false));
1616        assert_approx_equal!(230.125514343633f64, payment(0.0023, 50, 123.4567, -12345.67, true));
1617        assert_approx_equal!(-2.61666509117802f64, payment(0.0023, 50, 123.4567, 0.0, false));
1618        assert_approx_equal!(-4.9380223210177f64, payment(0.0023, 50, 123.4567, 123.4567, true));
1619        assert_approx_equal!(-259.333794436624f64, payment(0.0023, 50, 12345.67, -123.4567, false));
1620        assert_approx_equal!(-261.066057186273f64, payment(0.0023, 50, 12345.67, 0.0, true));
1621        assert_approx_equal!(-494.937977235604f64, payment(0.0023, 50, 12345.67, 12345.67, false));
1622        assert_approx_equal!(65.204553816131f64, payment(0.0023, 250, -12345.67, -123.4567, true));
1623        assert_approx_equal!(64.984929457009f64, payment(0.0023, 250, -12345.67, 1.234567, false));
1624        assert_approx_equal!(28.3298822707772f64, payment(0.0023, 250, -12345.67, 12345.67, true));
1625        assert_approx_equal!(0.653545242899081f64, payment(0.0023, 250, -123.4567, -1.234567, false));
1626        assert_approx_equal!(0.644743623003814f64, payment(0.0023, 250, -123.4567, 1.234567, true));
1627        assert_approx_equal!(36.6000466706714f64, payment(0.0023, 250, -1.234567, -12345.67, false));
1628        assert_approx_equal!(0.0101349033845735f64, payment(0.0023, 250, -1.234567, -1.234567, true));
1629        assert_approx_equal!(-0.359436619236723f64, payment(0.0023, 250, -1.234567, 123.4567, false));
1630        assert_approx_equal!(36.509575787479f64, payment(0.0023, 250, 0.0, -12345.67, true));
1631        assert_approx_equal!(0f64, payment(0.0023, 250, 0.0, 0.0, false));
1632        assert_approx_equal!(-0.36509575787479f64, payment(0.0023, 250, 0.0, 123.4567, true));
1633        assert_approx_equal!(0.359436619236723f64, payment(0.0023, 250, 1.234567, -123.4567, false));
1634        assert_approx_equal!(-0.00648394580582562f64, payment(0.0023, 250, 1.234567, 0.0, true));
1635        assert_approx_equal!(-36.6000466706714f64, payment(0.0023, 250, 1.234567, 12345.67, false));
1636        assert_approx_equal!(-0.283298822707772f64, payment(0.0023, 250, 123.4567, -123.4567, true));
1637        assert_approx_equal!(-0.653545242899081f64, payment(0.0023, 250, 123.4567, 1.234567, false));
1638        assert_approx_equal!(-37.1579703680616f64, payment(0.0023, 250, 123.4567, 12345.67, true));
1639        assert_approx_equal!(-64.984929457009f64, payment(0.0023, 250, 12345.67, -1.234567, false));
1640        assert_approx_equal!(-64.843109015835f64, payment(0.0023, 250, 12345.67, 1.234567, true));
1641        assert_approx_equal!(24413.7736168133f64, payment(0.023, 1, -12345.67, -12345.67, true));
1642        assert_approx_equal!(12629.62041f64, payment(0.023, 1, -12345.67, 0.0, false));
1643        assert_approx_equal!(12224.9889638319f64, payment(0.023, 1, -12345.67, 123.4567, true));
1644        assert_approx_equal!(249.7529041f64, payment(0.023, 1, -123.4567, -123.4567, false));
1645        assert_approx_equal!(123.4567f64, payment(0.023, 1, -123.4567, 0.0, true));
1646        assert_approx_equal!(-12219.3737959f64, payment(0.023, 1, -123.4567, 12345.67, false));
1647        assert_approx_equal!(121.915603168133f64, payment(0.023, 1, -1.234567, -123.4567, true));
1648        assert_approx_equal!(0.028395041f64, payment(0.023, 1, -1.234567, 1.234567, false));
1649        assert_approx_equal!(-12066.8690498133f64, payment(0.023, 1, -1.234567, 12345.67, true));
1650        assert_approx_equal!(1.234567f64, payment(0.023, 1, 0.0, -1.234567, false));
1651        assert_approx_equal!(-1.20681036168133f64, payment(0.023, 1, 0.0, 1.234567, true));
1652        assert_approx_equal!(12344.407037959f64, payment(0.023, 1, 1.234567, -12345.67, false));
1653        assert_approx_equal!(-0.0277566383186706f64, payment(0.023, 1, 1.234567, -1.234567, true));
1654        assert_approx_equal!(-124.719662041f64, payment(0.023, 1, 1.234567, 123.4567, false));
1655        assert_approx_equal!(11944.6469168133f64, payment(0.023, 1, 123.4567, -12345.67, true));
1656        assert_approx_equal!(-126.2962041f64, payment(0.023, 1, 123.4567, 0.0, false));
1657        assert_approx_equal!(-244.137736168133f64, payment(0.023, 1, 123.4567, 123.4567, true));
1658        assert_approx_equal!(-12506.16371f64, payment(0.023, 1, 12345.67, -123.4567, false));
1659        assert_approx_equal!(-12345.67f64, payment(0.023, 1, 12345.67, 0.0, true));
1660        assert_approx_equal!(-24975.29041f64, payment(0.023, 1, 12345.67, 12345.67, false));
1661        assert_approx_equal!(6302.67001787847f64, payment(0.023, 2, -12345.67, -123.4567, true));
1662        assert_approx_equal!(6385.99461810677f64, payment(0.023, 2, -12345.67, 1.234567, false));
1663        assert_approx_equal!(277.566383186706f64, payment(0.023, 2, -12345.67, 12345.67, true));
1664        assert_approx_equal!(64.4763142828967f64, payment(0.023, 2, -123.4567, -1.234567, false));
1665        assert_approx_equal!(61.8336103501328f64, payment(0.023, 2, -123.4567, 1.234567, true));
1666        assert_approx_equal!(6103.29313404248f64, payment(0.023, 2, -1.234567, -12345.67, false));
1667        assert_approx_equal!(1.2208464669705f64, payment(0.023, 2, -1.234567, -1.234567, true));
1668        assert_approx_equal!(-60.3878842471859f64, payment(0.023, 2, -1.234567, 123.4567, false));
1669        assert_approx_equal!(5965.44914325917f64, payment(0.023, 2, 0.0, -12345.67, true));
1670        assert_approx_equal!(0f64, payment(0.023, 2, 0.0, 0.0, false));
1671        assert_approx_equal!(-59.6544914325917f64, payment(0.023, 2, 0.0, 123.4567, true));
1672        assert_approx_equal!(60.3878842471859f64, payment(0.023, 2, 1.234567, -123.4567, false));
1673        assert_approx_equal!(-0.624301552644587f64, payment(0.023, 2, 1.234567, 0.0, true));
1674        assert_approx_equal!(-6103.29313404248f64, payment(0.023, 2, 1.234567, 12345.67, false));
1675        assert_approx_equal!(-2.77566383186706f64, payment(0.023, 2, 123.4567, -123.4567, true));
1676        assert_approx_equal!(-64.4763142828967f64, payment(0.023, 2, 123.4567, 1.234567, false));
1677        assert_approx_equal!(-6027.87929852363f64, payment(0.023, 2, 123.4567, 12345.67, true));
1678        assert_approx_equal!(-6385.99461810677f64, payment(0.023, 2, 12345.67, -1.234567, false));
1679        assert_approx_equal!(-6243.6120713602f64, payment(0.023, 2, 12345.67, 1.234567, true));
1680        assert_approx_equal!(5000.22243424033f64, payment(0.023, 5, -12345.67, -12345.67, false));
1681        assert_approx_equal!(2582.91518643341f64, payment(0.023, 5, -12345.67, -1.234567, true));
1682        assert_approx_equal!(2618.50506199896f64, payment(0.023, 5, -12345.67, 123.4567, false));
1683        assert_approx_equal!(2330.9451381636f64, payment(0.023, 5, -123.4567, -12345.67, true));
1684        assert_approx_equal!(26.4208642212016f64, payment(0.023, 5, -123.4567, 0.0, false));
1685        assert_approx_equal!(2.77566383186706f64, payment(0.023, 5, -123.4567, 123.4567, true));
1686        assert_approx_equal!(23.8455687634136f64, payment(0.023, 5, -1.234567, -123.4567, false));
1687        assert_approx_equal!(0.258268467460426f64, payment(0.023, 5, -1.234567, 0.0, true));
1688        assert_approx_equal!(-2357.87180347795f64, payment(0.023, 5, -1.234567, 12345.67, false));
1689        assert_approx_equal!(23.0511829141756f64, payment(0.023, 5, 0.0, -123.4567, true));
1690        assert_approx_equal!(-0.235813601212016f64, payment(0.023, 5, 0.0, 1.234567, false));
1691        assert_approx_equal!(-2305.11829141756f64, payment(0.023, 5, 0.0, 12345.67, true));
1692        assert_approx_equal!(-0.028395041f64, payment(0.023, 5, 1.234567, -1.234567, false));
1693        assert_approx_equal!(-0.488780296602182f64, payment(0.023, 5, 1.234567, 1.234567, true));
1694        assert_approx_equal!(2331.71514789896f64, payment(0.023, 5, 123.4567, -12345.67, false));
1695        assert_approx_equal!(-25.5963349169009f64, payment(0.023, 5, 123.4567, -1.234567, true));
1696        assert_approx_equal!(-50.0022243424032f64, payment(0.023, 5, 123.4567, 123.4567, false));
1697        assert_approx_equal!(-277.566383186706f64, payment(0.023, 5, 12345.67, -12345.67, true));
1698        assert_approx_equal!(-2642.08642212016f64, payment(0.023, 5, 12345.67, 0.0, false));
1699        assert_approx_equal!(-2605.73585751844f64, payment(0.023, 5, 12345.67, 123.4567, true));
1700        assert_approx_equal!(1407.18314215102f64, payment(0.023, 10, -12345.67, -123.4567, false));
1701        assert_approx_equal!(1364.67451221027f64, payment(0.023, 10, -12345.67, 0.0, true));
1702        assert_approx_equal!(283.95041f64, payment(0.023, 10, -12345.67, 12345.67, false));
1703        assert_approx_equal!(24.5178264123383f64, payment(0.023, 10, -123.4567, -123.4567, true));
1704        assert_approx_equal!(13.8494090983119f64, payment(0.023, 10, -123.4567, 1.234567, false));
1705        assert_approx_equal!(-1073.46138390146f64, payment(0.023, 10, -123.4567, 12345.67, true));
1706        assert_approx_equal!(0.250817364198221f64, payment(0.023, 10, -1.234567, -1.234567, false));
1707        assert_approx_equal!(0.0277566383186706f64, payment(0.023, 10, -1.234567, 1.234567, true));
1708        assert_approx_equal!(1112.1116159911f64, payment(0.023, 10, 0.0, -12345.67, false));
1709        assert_approx_equal!(0.108710812902356f64, payment(0.023, 10, 0.0, -1.234567, true));
1710        assert_approx_equal!(-11.121116159911f64, payment(0.023, 10, 0.0, 123.4567, false));
1711        assert_approx_equal!(1086.97166157234f64, payment(0.023, 10, 1.234567, -12345.67, true));
1712        assert_approx_equal!(-0.13960620259911f64, payment(0.023, 10, 1.234567, 0.0, false));
1713        assert_approx_equal!(-11.0075487414567f64, payment(0.023, 10, 1.234567, 123.4567, true));
1714        assert_approx_equal!(-2.8395041f64, payment(0.023, 10, 123.4567, -123.4567, false));
1715        assert_approx_equal!(-13.6467451221027f64, payment(0.023, 10, 123.4567, 0.0, true));
1716        assert_approx_equal!(-1126.07223625102f64, payment(0.023, 10, 123.4567, 12345.67, false));
1717        assert_approx_equal!(-1353.80343092003f64, payment(0.023, 10, 12345.67, -123.4567, true));
1718        assert_approx_equal!(-1396.1732371527f64, payment(0.023, 10, 12345.67, 1.234567, false));
1719        assert_approx_equal!(-2451.78264123383f64, payment(0.023, 10, 12345.67, 12345.67, true));
1720        assert_approx_equal!(418.072090469851f64, payment(0.023, 50, -12345.67, -1.234567, false));
1721        assert_approx_equal!(408.646401579592f64, payment(0.023, 50, -12345.67, 1.234567, true));
1722        assert_approx_equal!(138.288856439316f64, payment(0.023, 50, -123.4567, -12345.67, false));
1723        assert_approx_equal!(4.09970442169419f64, payment(0.023, 50, -123.4567, -1.234567, true));
1724        assert_approx_equal!(2.8395041f64, payment(0.023, 50, -123.4567, 123.4567, false));
1725        assert_approx_equal!(131.133993656746f64, payment(0.023, 50, -1.234567, -12345.67, true));
1726        assert_approx_equal!(0.0418058679642887f64, payment(0.023, 50, -1.234567, 0.0, false));
1727        assert_approx_equal!(-1.27006532596733f64, payment(0.023, 50, -1.234567, 123.4567, true));
1728        assert_approx_equal!(1.34108269642887f64, payment(0.023, 50, 0.0, -123.4567, false));
1729        assert_approx_equal!(0f64, payment(0.023, 50, 0.0, 0.0, true));
1730        assert_approx_equal!(-134.108269642887f64, payment(0.023, 50, 0.0, 12345.67, false));
1731        assert_approx_equal!(1.27006532596733f64, payment(0.023, 50, 1.234567, -123.4567, true));
1732        assert_approx_equal!(-0.0552166949285774f64, payment(0.023, 50, 1.234567, 1.234567, false));
1733        assert_approx_equal!(-131.133993656746f64, payment(0.023, 50, 1.234567, 12345.67, true));
1734        assert_approx_equal!(-4.16717596946458f64, payment(0.023, 50, 123.4567, -1.234567, false));
1735        assert_approx_equal!(-4.09970442169419f64, payment(0.023, 50, 123.4567, 1.234567, true));
1736        assert_approx_equal!(-283.95041f64, payment(0.023, 50, 12345.67, -12345.67, false));
1737        assert_approx_equal!(-408.646401579592f64, payment(0.023, 50, 12345.67, -1.234567, true));
1738        assert_approx_equal!(-419.399762339316f64, payment(0.023, 50, 12345.67, 123.4567, false));
1739        assert_approx_equal!(279.458579666982f64, payment(0.023, 250, -12345.67, -12345.67, true));
1740        assert_approx_equal!(284.918268499661f64, payment(0.023, 250, -12345.67, 0.0, false));
1741        assert_approx_equal!(278.503020444443f64, payment(0.023, 250, -12345.67, 123.4567, true));
1742        assert_approx_equal!(2.85886126999323f64, payment(0.023, 250, -123.4567, -123.4567, false));
1743        assert_approx_equal!(2.78512481426844f64, payment(0.023, 250, -123.4567, 0.0, true));
1744        assert_approx_equal!(1.8813241853352f64, payment(0.023, 250, -123.4567, 12345.67, false));
1745        assert_approx_equal!(0.0373122305440668f64, payment(0.023, 250, -1.234567, -123.4567, true));
1746        assert_approx_equal!(0.028395041f64, payment(0.023, 250, -1.234567, 1.234567, false));
1747        assert_approx_equal!(-0.918246991995591f64, payment(0.023, 250, -1.234567, 12345.67, true));
1748        assert_approx_equal!(9.67858499661454E-05f64, payment(0.023, 250, 0.0, -1.234567, false));
1749        assert_approx_equal!(-9.46098240138273E-05f64, payment(0.023, 250, 0.0, 1.234567, true));
1750        assert_approx_equal!(0.939366672811489f64, payment(0.023, 250, 1.234567, -12345.67, false));
1751        assert_approx_equal!(-0.0277566383186706f64, payment(0.023, 250, 1.234567, -1.234567, true));
1752        assert_approx_equal!(-0.0381704118465804f64, payment(0.023, 250, 1.234567, 123.4567, false));
1753        assert_approx_equal!(-1.83902657413021f64, payment(0.023, 250, 123.4567, -12345.67, true));
1754        assert_approx_equal!(-2.84918268499661f64, payment(0.023, 250, 123.4567, 0.0, false));
1755        assert_approx_equal!(-2.79458579666982f64, payment(0.023, 250, 123.4567, 123.4567, true));
1756        assert_approx_equal!(-284.908589914665f64, payment(0.023, 250, 12345.67, -123.4567, false));
1757        assert_approx_equal!(-278.512481426844f64, payment(0.023, 250, 12345.67, 0.0, true));
1758        assert_approx_equal!(-285.886126999323f64, payment(0.023, 250, 12345.67, 12345.67, false));
1759        assert_approx_equal!(15186.408667f64, payment(0.23, 1, -12345.67, -1.234567, false));
1760        assert_approx_equal!(12344.6662869919f64, payment(0.23, 1, -12345.67, 1.234567, true));
1761        assert_approx_equal!(12497.521741f64, payment(0.23, 1, -123.4567, -12345.67, false));
1762        assert_approx_equal!(124.46041300813f64, payment(0.23, 1, -123.4567, -1.234567, true));
1763        assert_approx_equal!(28.395041f64, payment(0.23, 1, -123.4567, 123.4567, false));
1764        assert_approx_equal!(10038.3646483008f64, payment(0.23, 1, -1.234567, -12345.67, true));
1765        assert_approx_equal!(1.51851741f64, payment(0.23, 1, -1.234567, 0.0, false));
1766        assert_approx_equal!(-99.1367338130081f64, payment(0.23, 1, -1.234567, 123.4567, true));
1767        assert_approx_equal!(123.4567f64, payment(0.23, 1, 0.0, -123.4567, false));
1768        assert_approx_equal!(0f64, payment(0.23, 1, 0.0, 0.0, true));
1769        assert_approx_equal!(-12345.67f64, payment(0.23, 1, 0.0, 12345.67, false));
1770        assert_approx_equal!(99.1367338130081f64, payment(0.23, 1, 1.234567, -123.4567, true));
1771        assert_approx_equal!(-2.75308441f64, payment(0.23, 1, 1.234567, 1.234567, false));
1772        assert_approx_equal!(-10038.3646483008f64, payment(0.23, 1, 1.234567, 12345.67, true));
1773        assert_approx_equal!(-150.617174f64, payment(0.23, 1, 123.4567, -1.234567, false));
1774        assert_approx_equal!(-124.46041300813f64, payment(0.23, 1, 123.4567, 1.234567, true));
1775        assert_approx_equal!(-2839.5041f64, payment(0.23, 1, 12345.67, -12345.67, false));
1776        assert_approx_equal!(-12344.6662869919f64, payment(0.23, 1, 12345.67, -1.234567, true));
1777        assert_approx_equal!(-15308.6308f64, payment(0.23, 1, 12345.67, 123.4567, false));
1778        assert_approx_equal!(11310.4503055161f64, payment(0.23, 2, -12345.67, -12345.67, true));
1779        assert_approx_equal!(8375.67898789238f64, payment(0.23, 2, -12345.67, 0.0, false));
1780        assert_approx_equal!(6764.48556017354f64, payment(0.23, 2, -12345.67, 123.4567, true));
1781        assert_approx_equal!(139.118538757848f64, payment(0.23, 2, -123.4567, -123.4567, false));
1782        assert_approx_equal!(68.0949511210762f64, payment(0.23, 2, -123.4567, 0.0, true));
1783        assert_approx_equal!(-5452.41809801345f64, payment(0.23, 2, -123.4567, 12345.67, false));
1784        assert_approx_equal!(45.6905014452951f64, payment(0.23, 2, -1.234567, -123.4567, true));
1785        assert_approx_equal!(0.28395041f64, payment(0.23, 2, -1.234567, 1.234567, false));
1786        assert_approx_equal!(-4500.27424389723f64, payment(0.23, 2, -1.234567, 12345.67, true));
1787        assert_approx_equal!(0.553617488789238f64, payment(0.23, 2, 0.0, -1.234567, false));
1788        assert_approx_equal!(-0.450095519340844f64, payment(0.23, 2, 0.0, 1.234567, true));
1789        assert_approx_equal!(5535.33731999359f64, payment(0.23, 2, 1.234567, -12345.67, false));
1790        assert_approx_equal!(-0.230853991869919f64, payment(0.23, 2, 1.234567, -1.234567, true));
1791        assert_approx_equal!(-56.199316777713f64, payment(0.23, 2, 1.234567, 123.4567, false));
1792        assert_approx_equal!(4432.86024228736f64, payment(0.23, 2, 123.4567, -12345.67, true));
1793        assert_approx_equal!(-83.7567898789238f64, payment(0.23, 2, 123.4567, 0.0, false));
1794        assert_approx_equal!(-113.104503055161f64, payment(0.23, 2, 123.4567, 123.4567, true));
1795        assert_approx_equal!(-8320.31723901346f64, payment(0.23, 2, 12345.67, -123.4567, false));
1796        assert_approx_equal!(-6809.49511210762f64, payment(0.23, 2, 12345.67, 0.0, true));
1797        assert_approx_equal!(-13911.8538757848f64, payment(0.23, 2, 12345.67, 12345.67, false));
1798        assert_approx_equal!(3592.96564272554f64, payment(0.23, 5, -12345.67, -123.4567, true));
1799        assert_approx_equal!(4403.54930414689f64, payment(0.23, 5, -12345.67, 1.234567, false));
1800        assert_approx_equal!(2308.53991869919f64, payment(0.23, 5, -12345.67, 12345.67, true));
1801        assert_approx_equal!(44.1934774055241f64, payment(0.23, 5, -123.4567, -1.234567, false));
1802        assert_approx_equal!(35.6753146997254f64, payment(0.23, 5, -123.4567, 1.234567, true));
1803        assert_approx_equal!(1564.64199488175f64, payment(0.23, 5, -1.234567, -12345.67, false));
1804        assert_approx_equal!(0.485195719399889f64, payment(0.23, 5, -1.234567, -1.234567, true));
1805        assert_approx_equal!(-15.2016456706623f64, payment(0.23, 5, -1.234567, 123.4567, false));
1806        assert_approx_equal!(1271.70863764985f64, payment(0.23, 5, 0.0, -12345.67, true));
1807        assert_approx_equal!(0f64, payment(0.23, 5, 0.0, 0.0, false));
1808        assert_approx_equal!(-12.7170863764985f64, payment(0.23, 5, 0.0, 123.4567, true));
1809        assert_approx_equal!(15.2016456706623f64, payment(0.23, 5, 1.234567, -123.4567, false));
1810        assert_approx_equal!(-0.358024855634904f64, payment(0.23, 5, 1.234567, 0.0, true));
1811        assert_approx_equal!(-1564.64199488175f64, payment(0.23, 5, 1.234567, 12345.67, false));
1812        assert_approx_equal!(-23.0853991869919f64, payment(0.23, 5, 123.4567, -123.4567, true));
1813        assert_approx_equal!(-44.1934774055241f64, payment(0.23, 5, 123.4567, 1.234567, false));
1814        assert_approx_equal!(-1307.51112321334f64, payment(0.23, 5, 123.4567, 12345.67, true));
1815        assert_approx_equal!(-4403.54930414689f64, payment(0.23, 5, 12345.67, -1.234567, false));
1816        assert_approx_equal!(-3580.3757272128f64, payment(0.23, 5, 12345.67, 1.234567, true));
1817        assert_approx_equal!(3659.46546285804f64, payment(0.23, 10, -12345.67, -12345.67, false));
1818        assert_approx_equal!(2641.89087763997f64, payment(0.23, 10, -12345.67, -1.234567, true));
1819        assert_approx_equal!(3245.38497461473f64, payment(0.23, 10, -12345.67, 123.4567, false));
1820        assert_approx_equal!(359.736202636836f64, payment(0.23, 10, -123.4567, -12345.67, true));
1821        assert_approx_equal!(32.4948478142902f64, payment(0.23, 10, -123.4567, 0.0, false));
1822        assert_approx_equal!(23.0853991869919f64, payment(0.23, 10, -123.4567, 123.4567, true));
1823        assert_approx_equal!(4.42475529243308f64, payment(0.23, 10, -1.234567, -123.4567, false));
1824        assert_approx_equal!(0.264185754587725f64, payment(0.23, 10, -1.234567, 0.0, true));
1825        assert_approx_equal!(-409.655732950875f64, payment(0.23, 10, -1.234567, 12345.67, false));
1826        assert_approx_equal!(3.33317627178063f64, payment(0.23, 10, 0.0, -123.4567, true));
1827        assert_approx_equal!(-0.0409980681429018f64, payment(0.23, 10, 0.0, 1.234567, false));
1828        assert_approx_equal!(-333.317627178063f64, payment(0.23, 10, 0.0, 12345.67, true));
1829        assert_approx_equal!(-0.28395041f64, payment(0.23, 10, 1.234567, -1.234567, false));
1830        assert_approx_equal!(-0.297517517305531f64, payment(0.23, 10, 1.234567, 1.234567, true));
1831        assert_approx_equal!(377.485833614727f64, payment(0.23, 10, 123.4567, -12345.67, false));
1832        assert_approx_equal!(-26.3852436960547f64, payment(0.23, 10, 123.4567, -1.234567, true));
1833        assert_approx_equal!(-36.5946546285804f64, payment(0.23, 10, 123.4567, 123.4567, false));
1834        assert_approx_equal!(-2308.53991869919f64, payment(0.23, 10, 12345.67, -12345.67, true));
1835        assert_approx_equal!(-3249.48478142902f64, payment(0.23, 10, 12345.67, 0.0, false));
1836        assert_approx_equal!(-2645.19072214903f64, payment(0.23, 10, 12345.67, 123.4567, true));
1837        assert_approx_equal!(2839.59579004515f64, payment(0.23, 50, -12345.67, -123.4567, false));
1838        assert_approx_equal!(2308.61372538449f64, payment(0.23, 50, -12345.67, 0.0, true));
1839        assert_approx_equal!(2839.5041f64, payment(0.23, 50, -12345.67, 12345.67, false));
1840        assert_approx_equal!(23.0868753206979f64, payment(0.23, 50, -123.4567, -123.4567, true));
1841        assert_approx_equal!(28.3959397440069f64, payment(0.23, 50, -123.4567, 1.234567, false));
1842        assert_approx_equal!(23.0123305685425f64, payment(0.23, 50, -123.4567, 12345.67, true));
1843        assert_approx_equal!(0.283968566444584f64, payment(0.23, 50, -1.234567, -1.234567, false));
1844        assert_approx_equal!(0.230853991869919f64, payment(0.23, 50, -1.234567, 1.234567, true));
1845        assert_approx_equal!(0.0907822229220255f64, payment(0.23, 50, 0.0, -12345.67, false));
1846        assert_approx_equal!(7.38066853025501E-06f64, payment(0.23, 50, 0.0, -1.234567, true));
1847        assert_approx_equal!(-0.000907822229219732f64, payment(0.23, 50, 0.0, 123.4567, false));
1848        assert_approx_equal!(-0.157054687235803f64, payment(0.23, 50, 1.234567, -12345.67, true));
1849        assert_approx_equal!(-0.283959488222292f64, payment(0.23, 50, 1.234567, 0.0, false));
1850        assert_approx_equal!(-0.231599439391473f64, payment(0.23, 50, 1.234567, 123.4567, true));
1851        assert_approx_equal!(-28.395041f64, payment(0.23, 50, 123.4567, -123.4567, false));
1852        assert_approx_equal!(-23.0861372538449f64, payment(0.23, 50, 123.4567, 0.0, true));
1853        assert_approx_equal!(-28.4867310451513f64, payment(0.23, 50, 123.4567, 12345.67, false));
1854        assert_approx_equal!(-2308.61298731764f64, payment(0.23, 50, 12345.67, -123.4567, true));
1855        assert_approx_equal!(-2839.59489130114f64, payment(0.23, 50, 12345.67, 1.234567, false));
1856        assert_approx_equal!(-2308.68753206979f64, payment(0.23, 50, 12345.67, 12345.67, true));
1857        assert_approx_equal!(2839.5041f64, payment(0.23, 250, -12345.67, -1.234567, false));
1858        assert_approx_equal!(2308.53991869919f64, payment(0.23, 250, -12345.67, 1.234567, true));
1859        assert_approx_equal!(28.3950410000001f64, payment(0.23, 250, -123.4567, -12345.67, false));
1860        assert_approx_equal!(23.0853991869919f64, payment(0.23, 250, -123.4567, -1.234567, true));
1861        assert_approx_equal!(28.395041f64, payment(0.23, 250, -123.4567, 123.4567, false));
1862        assert_approx_equal!(0.230853991869828f64, payment(0.23, 250, -1.234567, -12345.67, true));
1863        assert_approx_equal!(0.28395041f64, payment(0.23, 250, -1.234567, 0.0, false));
1864        assert_approx_equal!(0.230853991869918f64, payment(0.23, 250, -1.234567, 123.4567, true));
1865        assert_approx_equal!(0f64, payment(0.23, 250, 0.0, -123.4567, false));
1866        assert_approx_equal!(0f64, payment(0.23, 250, 0.0, 0.0, true));
1867        assert_approx_equal!(0f64, payment(0.23, 250, 0.0, 12345.67, false));
1868        assert_approx_equal!(-0.230853991869918f64, payment(0.23, 250, 1.234567, -123.4567, true));
1869        assert_approx_equal!(-0.28395041f64, payment(0.23, 250, 1.234567, 1.234567, false));
1870        assert_approx_equal!(-0.230853991869828f64, payment(0.23, 250, 1.234567, 12345.67, true));
1871        assert_approx_equal!(-28.395041f64, payment(0.23, 250, 123.4567, -1.234567, false));
1872        assert_approx_equal!(-23.0853991869919f64, payment(0.23, 250, 123.4567, 1.234567, true));
1873        assert_approx_equal!(-2839.5041f64, payment(0.23, 250, 12345.67, -12345.67, false));
1874        assert_approx_equal!(-2308.53991869919f64, payment(0.23, 250, 12345.67, -1.234567, true));
1875        assert_approx_equal!(-2839.5041f64, payment(0.23, 250, 12345.67, 123.4567, false));
1876    }
1877
1878}
1879