@@ -397,25 +397,29 @@ namespace te_builtins
397
397
static te_type te_sum (te_type val1, te_type val2, te_type val3, te_type val4, te_type val5,
398
398
te_type val6, te_type val7)
399
399
{
400
- return (!std::isfinite (val1) ? 0 : val1) + (!std::isfinite (val2) ? 0 : val2) +
401
- (!std::isfinite (val3) ? 0 : val3) + (!std::isfinite (val4) ? 0 : val4) +
402
- (!std::isfinite (val5) ? 0 : val5) + (!std::isfinite (val6) ? 0 : val6) +
403
- (!std::isfinite (val7) ? 0 : val7);
400
+ const auto getSumMaybeNan = [](const auto val) { return (!std::isfinite (val) ? 0 : val); };
401
+
402
+ return getSumMaybeNan (val1) + getSumMaybeNan (val2) +
403
+ getSumMaybeNan (val3)+ getSumMaybeNan (val4) +
404
+ getSumMaybeNan (val5) + getSumMaybeNan (val6) +
405
+ getSumMaybeNan (val7);
404
406
}
405
407
406
408
[[nodiscard]]
407
409
static te_type te_average (te_type val1, te_type val2, te_type val3, te_type val4, te_type val5,
408
410
te_type val6, te_type val7)
409
411
{
410
- const auto validN = (!std::isfinite (val1) ? 0 : 1 ) + (!std::isfinite (val2) ? 0 : 1 ) +
411
- (!std::isfinite (val3) ? 0 : 1 ) + (!std::isfinite (val4) ? 0 : 1 ) +
412
- (!std::isfinite (val5) ? 0 : 1 ) + (!std::isfinite (val6) ? 0 : 1 ) +
413
- (!std::isfinite (val7) ? 0 : 1 );
412
+ const auto isValidMaybeNan = [](const auto val) { return (!std::isfinite (val) ? 0 : 1 ); };
413
+
414
+ const auto validN = isValidMaybeNan (val1) + isValidMaybeNan (val2) +
415
+ isValidMaybeNan (val3) + isValidMaybeNan (val4) +
416
+ isValidMaybeNan (val5) + isValidMaybeNan (val6) +
417
+ isValidMaybeNan (val7);
414
418
const auto total = te_sum (val1, val2, val3, val4, val5, val6, val7);
415
419
return te_divide (total, static_cast <te_type>(validN));
416
420
}
417
421
418
- // / @warning This version of round emulates Excel behavior of supporting
422
+ // / @warning This version of round emulates Excel's behavior of supporting
419
423
// / negative decimal places (e.g., ROUND(21.5, -1) = 20). Be aware
420
424
// / of that if using this function outside of TinyExpr++.
421
425
[[nodiscard]]
0 commit comments