@@ -4244,14 +4244,15 @@ TEST_CASE("PV", "[finance]")
42444244 CHECK_THAT (WITHIN_TYPE_CAST (tep.evaluate (" PV(-0.5, 5, -100)" )),
42454245 Catch::Matchers::WithinRel (WITHIN_TYPE_CAST (6200 ), WITHIN_TYPE_CAST (0.0001 )));
42464246
4247- // Excel: =PV(-1, 10, -100) -> #NUM!
4248- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PV(-1, 10, -100)" ))));
4247+ CHECK_THAT (
4248+ WITHIN_TYPE_CAST ((tep.evaluate (" PV(0.05, 0, -100)" ))),
4249+ Catch::Matchers::WithinRel (WITHIN_TYPE_CAST (0 ), WITHIN_TYPE_CAST (0.0001 )));
42494250
4250- // Excel: = PV(0.05, 0 , -100) -> #NUM!
4251- CHECK ( std::isnan (WITHIN_TYPE_CAST (tep. evaluate ( " PV(0.05, 0, -100) " ) )));
4251+ CHECK_THAT ( WITHIN_TYPE_CAST (tep. evaluate ( " PV(0.05, -10 , -100)" )),
4252+ Catch::Matchers::WithinRel (WITHIN_TYPE_CAST (- 1257.78925355488 ), WITHIN_TYPE_CAST ( 0.0001 )));
42524253
4253- // Excel: =PV(0.05, - 10, -100) -> #NUM!
4254- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PV(0.05, - 10, -100)" ))));
4254+ // Excel: =PV(-1, 10, -100) -> #NUM!
4255+ CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PV(-1, 10, -100)" ))));
42554256
42564257 // Excel: =PV(NaN, 10, -100) -> #NUM!
42574258 CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PV(NaN, 10, -100)" ))));
@@ -4307,7 +4308,7 @@ TEST_CASE("PMT", "[finance]")
43074308 WITHIN_TYPE_CAST (tep.evaluate (" PMT(0.05/12, 60, 10000, 0, 1)" )),
43084309 Catch::Matchers::WithinRel (
43094310 WITHIN_TYPE_CAST (-187.93 ),
4310- WITHIN_TYPE_CAST (0.00001 )));
4311+ WITHIN_TYPE_CAST (0.001 )));
43114312
43124313 // Excel: =PMT(0, 60, 12000)
43134314 // Zero interest: straight-line repayment
@@ -4317,6 +4318,11 @@ TEST_CASE("PMT", "[finance]")
43174318 Catch::Matchers::WithinRel (
43184319 WITHIN_TYPE_CAST (-200 )));
43194320
4321+ CHECK_THAT (
4322+ WITHIN_TYPE_CAST (tep.evaluate (" PMT(-1, 60, 12000)" )),
4323+ Catch::Matchers::WithinRel (
4324+ WITHIN_TYPE_CAST (0 )));
4325+
43204326 // Excel: =PMT(0.1, 1, 100)
43214327 // One-period loan at 10%
43224328 // Excel result = -110
@@ -4333,7 +4339,7 @@ TEST_CASE("PMT", "[finance]")
43334339 WITHIN_TYPE_CAST (tep.evaluate (" PMT(0.05/12, 60, 10000, 1000)" )),
43344340 Catch::Matchers::WithinRel (
43354341 WITHIN_TYPE_CAST (-203.42 ),
4336- WITHIN_TYPE_CAST (0.00002 )));
4342+ WITHIN_TYPE_CAST (0.001 )));
43374343
43384344 // Excel data:
43394345 // Annual interest rate: 8%
@@ -4372,13 +4378,17 @@ TEST_CASE("PMT", "[finance]")
43724378 WITHIN_TYPE_CAST (-129.08 ),
43734379 WITHIN_TYPE_CAST (0.00005 )));
43744380
4381+ CHECK_THAT (
4382+ WITHIN_TYPE_CAST (tep.evaluate (" PMT(0.05, -10, 1000)" )),
4383+ Catch::Matchers::WithinRel (
4384+ WITHIN_TYPE_CAST (79.5045749654567 ),
4385+ WITHIN_TYPE_CAST (0.00001 )));
4386+
43754387 // Excel: rate <= -1 -> #NUM!
4376- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PMT(-1, 10, 1000)" ))));
43774388 CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PMT(-1.5, 10, 1000)" ))));
43784389
43794390 // Excel: nper <= 0 -> #NUM!
43804391 CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PMT(0.05, 0, 1000)" ))));
4381- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PMT(0.05, -10, 1000)" ))));
43824392
43834393 // Non-finite args -> NaN
43844394 CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" PMT(NaN, 10, 1000)" ))));
@@ -4575,13 +4585,29 @@ TEST_CASE("FV", "[finance]")
45754585 WITHIN_TYPE_CAST (2301.40 ),
45764586 WITHIN_TYPE_CAST (0.00005 )));
45774587
4578- // Excel: rate <= -1 -> #NUM!
4579- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" FV(-1, 10, -100)" ))));
4580- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" FV(-1.5, 10, -100)" ))));
4588+ CHECK_THAT (
4589+ WITHIN_TYPE_CAST (tep.evaluate (" FV(-1, 10, -100)" )),
4590+ Catch::Matchers::WithinRel (
4591+ WITHIN_TYPE_CAST (100 ),
4592+ WITHIN_TYPE_CAST (0.00005 )));
45814593
4582- // Excel: nper <= 0 -> #NUM!
4583- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" FV(0.05, 0, -100)" ))));
4584- CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" FV(0.05, -10, -100)" ))));
4594+ CHECK_THAT (
4595+ WITHIN_TYPE_CAST (tep.evaluate (" FV(-1.5, 10, -100)" )),
4596+ Catch::Matchers::WithinRel (
4597+ WITHIN_TYPE_CAST (66.6015625 ),
4598+ WITHIN_TYPE_CAST (0.00005 )));
4599+
4600+ CHECK_THAT (
4601+ WITHIN_TYPE_CAST (tep.evaluate (" FV(0.05, 0, -100)" )),
4602+ Catch::Matchers::WithinRel (
4603+ WITHIN_TYPE_CAST (0 ),
4604+ WITHIN_TYPE_CAST (0.00005 )));
4605+
4606+ CHECK_THAT (
4607+ WITHIN_TYPE_CAST (tep.evaluate (" FV(0.05, -10, -100)" )),
4608+ Catch::Matchers::WithinRel (
4609+ WITHIN_TYPE_CAST (-772.173492918482 ),
4610+ WITHIN_TYPE_CAST (0.00005 )));
45854611
45864612 // Non-finite args -> NaN
45874613 CHECK (std::isnan (WITHIN_TYPE_CAST (tep.evaluate (" FV(NaN, 10, -100)" ))));
0 commit comments