diff --git a/src/utils/bigint.js b/src/utils/bigint.js index 4a163cfdfa..f77c705570 100644 --- a/src/utils/bigint.js +++ b/src/utils/bigint.js @@ -22,6 +22,11 @@ export function promoteLogarithm (log16, numberLog, config, cplx) { const s15 = s.substring(0, 15) return log16 * (s.length - s15.length) + numberLog(Number('0x' + s15)) } - return cplx(b.toNumber()) + + if (b === 0n) { + return -Infinity + } + + return cplx(Number(b)) } } diff --git a/test/unit-tests/function/arithmetic/log.test.js b/test/unit-tests/function/arithmetic/log.test.js index 3ad86017b2..f687c98f0c 100644 --- a/test/unit-tests/function/arithmetic/log.test.js +++ b/test/unit-tests/function/arithmetic/log.test.js @@ -5,6 +5,7 @@ import { approxDeepEqual } from '../../../../tools/approx.js' import math from '../../../../src/defaultInstance.js' const mathPredictable = math.create({ predictable: true }) const complex = math.complex +const bignumber = math.bignumber const matrix = math.matrix const unit = math.unit const fraction = math.fraction @@ -36,7 +37,17 @@ describe('log', function () { }) it('should return the log of zero', function () { - approxDeepEqual(log(0), -Infinity) + assert.deepStrictEqual(log(0), -Infinity) + assert.deepStrictEqual(log(0n), -Infinity) + assert.deepStrictEqual(log(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(log(false), -Infinity) + }) + + it('should return the log of zero with predicable:true', function () { + assert.deepStrictEqual(mathPredictable.log(0), -Infinity) + assert.deepStrictEqual(mathPredictable.log(0n), NaN) + assert.deepStrictEqual(mathPredictable.log(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(mathPredictable.log(false), -Infinity) }) it('should return the log base N of a number', function () { diff --git a/test/unit-tests/function/arithmetic/log10.test.js b/test/unit-tests/function/arithmetic/log10.test.js index e8e7682a4a..547d718b29 100644 --- a/test/unit-tests/function/arithmetic/log10.test.js +++ b/test/unit-tests/function/arithmetic/log10.test.js @@ -5,6 +5,7 @@ import { approxDeepEqual } from '../../../../tools/approx.js' import math from '../../../../src/defaultInstance.js' const mathPredictable = math.create({ predictable: true }) const complex = math.complex +const bignumber = math.bignumber const matrix = math.matrix const unit = math.unit const log10 = math.log10 @@ -40,7 +41,17 @@ describe('log10', function () { }) it('should return the log base 10 of zero', function () { - approxDeepEqual(log10(0), -Infinity) + assert.deepStrictEqual(log10(0), -Infinity) + assert.deepStrictEqual(log10(0n), -Infinity) + assert.deepStrictEqual(log10(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(log10(false), -Infinity) + }) + + it('should return the log base 10 of zero with predicable:true', function () { + assert.deepStrictEqual(mathPredictable.log10(0), -Infinity) + assert.deepStrictEqual(mathPredictable.log10(0n), NaN) + assert.deepStrictEqual(mathPredictable.log10(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(mathPredictable.log10(false), -Infinity) }) it('should return the log of positive bignumbers', function () { diff --git a/test/unit-tests/function/arithmetic/log2.test.js b/test/unit-tests/function/arithmetic/log2.test.js index 332636dded..a743fbea37 100644 --- a/test/unit-tests/function/arithmetic/log2.test.js +++ b/test/unit-tests/function/arithmetic/log2.test.js @@ -5,6 +5,7 @@ import { approxDeepEqual } from '../../../../tools/approx.js' import math from '../../../../src/defaultInstance.js' const mathPredictable = math.create({ predictable: true }) const complex = math.complex +const bignumber = math.bignumber const matrix = math.matrix const unit = math.unit const log2 = math.log2 @@ -38,7 +39,17 @@ describe('log2', function () { }) it('should return the log base 2 of zero', function () { - approxDeepEqual(log2(0), -Infinity) + assert.deepStrictEqual(log2(0), -Infinity) + assert.deepStrictEqual(log2(0n), -Infinity) + assert.deepStrictEqual(log2(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(log2(false), -Infinity) + }) + + it('should return the log base 2 of zero with predicable:true', function () { + assert.deepStrictEqual(mathPredictable.log2(0), -Infinity) + assert.deepStrictEqual(mathPredictable.log2(0n), NaN) + assert.deepStrictEqual(mathPredictable.log2(bignumber('0')), bignumber('-Infinity')) + assert.deepStrictEqual(mathPredictable.log2(false), -Infinity) }) it('should return the log of positive bignumbers', function () {