From 899ead501295e286d49199a01b7970d216320238 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 18 Dec 2024 13:39:37 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20up=20results=20of=20b=E2=8B=86=E2=81=BCx?= =?UTF-8?q?=20with=20integer=20b=20and=20near-integer=20result?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bqn.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/bqn.js b/docs/bqn.js index 4818ea82..7ac27ee0 100644 --- a/docs/bqn.js +++ b/docs/bqn.js @@ -270,7 +270,16 @@ let power = (x,w) => { let log = (x,w) => { if (isnum(x)) { if (!has(w)) return Math.log(x); - if (isnum(w)) return Math.log(x)/Math.log(w); + if (isnum(w)) { + let r = Math.log(x) / Math.log(w); + if (w == Math.floor(w)) { // Avoid bad floor or ceiling of log + let u = 4.440892098500626e-16 * r; + let rr = Math.round(r), rd = Math.abs(r-rr); + let sgd = (x,y) => (x > y) - (x < y); + if (rd <= u && sgd(x,Math.round(x)) != sgd(r,rr)) r = rr; + } + return r; + } } throw Error("⋆⁼: Arguments must be numbers"); }