import assert from 'assert' import math from '#nanomath' import {ReturnTyping} from '#core/Type.js' describe('number arithmetic', () => { it('supports basic operations', () => { assert.strictEqual(math.abs(-Infinity), Infinity) assert(isNaN(math.norm(NaN))) assert.strictEqual(math.normsq(-2), 4) assert.strictEqual(math.add(2, 2), 4) assert.strictEqual(math.divide(6, 4), 1.5) assert.strictEqual(math.cbrt(-8), -2) assert.strictEqual(math.invert(-4), -0.25) assert.strictEqual(math.multiply(4, 1.5), 6) assert.strictEqual(math.negate(Infinity), -Infinity) assert.strictEqual(math.subtract(4, 2), 2) assert.strictEqual(math.quotient(7, 3), 2) }) it('takes square root of numbers appropriately', () => { assert(isNaN(math.sqrt(NaN))) assert.strictEqual(math.sqrt(4), 2) assert.deepStrictEqual(math.sqrt(-4), math.complex(0, 2)) math.config.returnTyping = ReturnTyping.conservative assert(isNaN(math.sqrt(NaN))) assert.strictEqual(math.sqrt(4), 2) assert(isNaN(math.sqrt(-4))) math.config.returnTyping = ReturnTyping.full assert(isNaN(math.sqrt(NaN))) assert.deepStrictEqual(math.sqrt(4), math.complex(2, 0)) assert.deepStrictEqual(math.sqrt(-4), math.complex(0, 2)) math.config.returnTyping = ReturnTyping.free }) })