From bd02e7e3943ba0e22346b218b86887d17e9cbe2e Mon Sep 17 00:00:00 2001 From: Dan Simon Date: Thu, 9 Feb 2023 13:50:59 -0500 Subject: [PATCH] Codefactor changes, comment improvement --- javascripts/core/math.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/javascripts/core/math.js b/javascripts/core/math.js index 390c24747..3a36ec2ae 100644 --- a/javascripts/core/math.js +++ b/javascripts/core/math.js @@ -514,13 +514,14 @@ window.logFactorial = (function() { }; }()); -window.exp1m = function (x) { +window.exp1m = function(x) { if (x.abs().gte(0.001)) { return x.exp().minus(1); - } else { - // Probably just figuring out these are the only terms needed is faster than calculating all the terms. - return x.plus(x.pow(2).div(2)).plus(x.pow(3).div(6)).plus(x.pow(4).div(24)).plus(x.pow(5).div(120)); } + // This sum contains all the terms that are relevant for |x| < 0.001. We could do some sort of loop + // (add terms as long as they matter) but that probably has a greater fixed overhead, and we don't + // call this enough for efficiency to be very worrying anyway. + return x.plus(x.pow(2).div(2)).plus(x.pow(3).div(6)).plus(x.pow(4).div(24)).plus(x.pow(5).div(120)); }; /** 32 bit XORSHIFT generator */