feat: Implement subtypes
This should eventually be moved into typed-function itself, but for now it can be implemented on top of the existing typed-function. Uses subtypes to define (and error-check) gcd and lcm, which are only defined for integer arguments. Resolves #36.
This commit is contained in:
parent
4d38f4161c
commit
c429c19dfe
35 changed files with 294 additions and 43 deletions
13
src/bigint/quotient.mjs
Normal file
13
src/bigint/quotient.mjs
Normal file
|
@ -0,0 +1,13 @@
|
|||
export * from './Types/bigint.mjs'
|
||||
|
||||
/* Returns the best integer approximation to n/d */
|
||||
export const quotient = {
|
||||
'bigint,bigint': ({'sign(bigint)': sgn}) => (n, d) => {
|
||||
const dSgn = sgn(d)
|
||||
if (dSgn === 0n) return 0n
|
||||
if (sgn(n) === dSgn) return n/d
|
||||
const quot = n/d
|
||||
if (quot * d == n) return quot
|
||||
return quot - 1n
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue