feat: add the rest of relational from pocomath
All checks were successful
/ test (pull_request) Successful in 18s
All checks were successful
/ test (pull_request) Successful in 18s
This commit is contained in:
parent
c1791ddc20
commit
92ac7f38ae
2 changed files with 49 additions and 0 deletions
|
@ -59,4 +59,24 @@ describe('generic relational functions', () => {
|
|||
assert.throws(() => sign(false), TypeError)
|
||||
assert.throws(() => sign(undefined), ResolutionError)
|
||||
})
|
||||
it('computes inequalities', () => {
|
||||
const {unequal, larger, largerEq, smaller, smallerEq} = math
|
||||
assert(!unequal(undefined, undefined))
|
||||
assert(!unequal(math.types.NumberT, math.types.NumberT))
|
||||
assert(unequal(math.types.NumberT, math.types.BooleanT))
|
||||
assert(unequal(undefined, math.types.NumberT))
|
||||
assert(!unequal(1, 1))
|
||||
assert(!unequal(true, 1)) // questionable but same as mathjs
|
||||
assert(unequal(undefined, true))
|
||||
assert(!unequal(1, 1 + 0.9e-12))
|
||||
assert(!unequal(0, 1e-16))
|
||||
assert(unequal(1, 1 + 1.1e-12))
|
||||
assert(unequal(0, 1.1e-15))
|
||||
assert(larger(true, 0.5))
|
||||
assert(!larger(3 + 1e-16, 3))
|
||||
assert(largerEq(0.5, false))
|
||||
assert(largerEq(3 + 1e-16, 3))
|
||||
assert(smallerEq(3 + 1e-16, 3))
|
||||
assert(!smaller(3, 3 + 1e-16))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -75,3 +75,32 @@ export const sign = onType(Any, (math, T) => {
|
|||
const comp = math.compare.resolve([T, T])
|
||||
return ReturnsAs(comp, t => comp(t, zero))
|
||||
})
|
||||
|
||||
export const unequal = (math, types) => {
|
||||
const eq = math.equal.resolve(types)
|
||||
return ReturnsAs(eq, (...args) => !eq(...args))
|
||||
}
|
||||
|
||||
export const larger = onType([Any, Any], (math, [T, U]) => {
|
||||
const eq = math.equal.resolve([T, U])
|
||||
const bigger = math.exceeds.resolve([T, U])
|
||||
return boolnum((t, u) => !eq(t, u) && bigger(t, u))(math)
|
||||
})
|
||||
|
||||
export const largerEq = onType([Any, Any], (math, [T, U]) => {
|
||||
const eq = math.equal.resolve([T, U])
|
||||
const bigger = math.exceeds.resolve([T, U])
|
||||
return ReturnsAs(bigger, (t, u) => eq(t, u) || bigger(t, u))
|
||||
})
|
||||
|
||||
export const smaller = onType([Any, Any], (math, [T, U]) => {
|
||||
const eq = math.equal.resolve([T, U])
|
||||
const bigger = math.exceeds.resolve([U, T])
|
||||
return boolnum((t, u) => !eq(t, u) && bigger(u, t))(math)
|
||||
})
|
||||
|
||||
export const smallerEq = onType([Any, Any], (math, [T, U]) => {
|
||||
const eq = math.equal.resolve([T, U])
|
||||
const bigger = math.exceeds.resolve([U, T])
|
||||
return ReturnsAs(bigger, (t, u) => eq(t, u) || bigger(u, t))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue