2025-04-16 04:23:48 +00:00
|
|
|
import assert from 'assert'
|
|
|
|
import math from '#nanomath'
|
2025-04-25 14:17:34 +00:00
|
|
|
import {NumberT} from '#number/NumberT.js'
|
2025-04-16 04:23:48 +00:00
|
|
|
|
|
|
|
describe('generic utility functions', () => {
|
|
|
|
it('tests whether an element is zero', () => {
|
|
|
|
const {isZero} = math
|
|
|
|
assert(!isZero(3))
|
|
|
|
assert(isZero(3e-16))
|
|
|
|
assert(isZero(false))
|
|
|
|
assert(!isZero(true))
|
|
|
|
assert(isZero(undefined))
|
2025-04-25 14:17:34 +00:00
|
|
|
assert(isZero(math.types.Complex(NumberT).zero))
|
|
|
|
assert(isZero(math.complex(-2e-16, 4e-17)))
|
|
|
|
assert(!isZero(math.complex(true)))
|
|
|
|
})
|
|
|
|
it('tests whether an element is real', () => {
|
|
|
|
const {isReal} = math
|
|
|
|
assert(isReal(Infinity))
|
|
|
|
assert(isReal(false))
|
|
|
|
assert(isReal(math.types.Complex(NumberT).one))
|
|
|
|
assert(isReal(math.complex(-3.25, 4e-16)))
|
|
|
|
assert(!isReal(math.complex(3, 4)))
|
2025-04-16 04:23:48 +00:00
|
|
|
})
|
|
|
|
})
|