feat: Add return typing strategies and implement sqrt with them (#26)
All checks were successful
/ test (push) Successful in 17s
All checks were successful
/ test (push) Successful in 17s
Resolves #25 Reviewed-on: #26 Co-authored-by: Glen Whitney <glen@studioinfinity.org> Co-committed-by: Glen Whitney <glen@studioinfinity.org>
This commit is contained in:
parent
aad62df8ac
commit
0765ba7202
35 changed files with 1125 additions and 152 deletions
|
@ -1,5 +1,6 @@
|
|||
import assert from 'assert'
|
||||
import math from '#nanomath'
|
||||
import {ReturnTyping} from '#core/Type.js'
|
||||
|
||||
describe('number arithmetic', () => {
|
||||
it('supports basic operations', () => {
|
||||
|
@ -14,4 +15,18 @@ describe('number arithmetic', () => {
|
|||
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
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue