Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/utils/bigint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
13 changes: 12 additions & 1 deletion test/unit-tests/function/arithmetic/log.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down
13 changes: 12 additions & 1 deletion test/unit-tests/function/arithmetic/log10.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down
13 changes: 12 additions & 1 deletion test/unit-tests/function/arithmetic/log2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 () {
Expand Down