feat(floor): Provide example of op-centric organization
This commit is contained in:
parent
fe54bc6004
commit
7d1a435aa0
11 changed files with 65 additions and 8 deletions
|
@ -1,5 +1,6 @@
|
|||
import PocomathInstance from '../core/PocomathInstance.mjs'
|
||||
import * as bigints from './native.mjs'
|
||||
import * as generic from '../generic/all.mjs'
|
||||
import * as floor from '../ops/floor.mjs'
|
||||
|
||||
export default PocomathInstance.merge('bigint', bigints, generic)
|
||||
export default PocomathInstance.merge('bigint', bigints, generic, floor)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import PocomathInstance from '../core/PocomathInstance.mjs'
|
||||
import * as complexes from './native.mjs'
|
||||
import * as generic from '../generic/arithmetic.mjs'
|
||||
import * as floor from '../ops/floor.mjs'
|
||||
|
||||
export default PocomathInstance.merge('complex', complexes, generic)
|
||||
export default PocomathInstance.merge('complex', complexes, generic, floor)
|
||||
|
|
|
@ -471,6 +471,7 @@ export default class PocomathInstance {
|
|||
}
|
||||
|
||||
for (const instType of instantiationSet) {
|
||||
if (!(instType in this.Types)) continue
|
||||
if (this.Types[instType] === anySpec) continue
|
||||
const signature =
|
||||
substituteInSig(trimSignature, theTemplateParam, instType)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import PocomathInstance from '../core/PocomathInstance.mjs'
|
||||
import * as numbers from './native.mjs'
|
||||
import * as generic from '../generic/all.mjs'
|
||||
import * as floor from '../ops/floor.mjs'
|
||||
|
||||
export default PocomathInstance.merge('number', numbers, generic)
|
||||
export default PocomathInstance.merge('number', numbers, generic, floor)
|
||||
|
||||
|
|
25
src/ops/floor.mjs
Normal file
25
src/ops/floor.mjs
Normal file
|
@ -0,0 +1,25 @@
|
|||
import {Complex} from '../complex/Types/Complex.mjs'
|
||||
|
||||
/* Note we don't **export** any types here, so that only the options
|
||||
* below that correspond to types that have been installed are activated.
|
||||
*/
|
||||
|
||||
export const floor = {
|
||||
bigint: () => x => x,
|
||||
NumInt: () => x => x, // Because Pocomath isn't part of typed-function, or
|
||||
GaussianInteger: () => x => x, // at least have access to the real
|
||||
// typed-function parse, we unfortunately can't coalesce these into one
|
||||
// entry with type `bigint|NumInt|GaussianInteger` because they couldn't
|
||||
// be separately activated then
|
||||
|
||||
number: ({'equal(number,number)': eq}) => n => {
|
||||
if (eq(n, Math.round(n))) return Math.round(n)
|
||||
return Math.floor(n)
|
||||
},
|
||||
|
||||
Complex: Complex.promoteUnary.Complex,
|
||||
|
||||
// OK to include a type totally not in Pocomath yet, it'll never be
|
||||
// activated.
|
||||
Fraction: ({quotient}) => f => quotient(f.n, f.d),
|
||||
}
|
|
@ -4,7 +4,9 @@ import * as numbers from './number/native.mjs'
|
|||
import * as bigints from './bigint/native.mjs'
|
||||
import * as complex from './complex/native.mjs'
|
||||
import * as generic from './generic/all.mjs'
|
||||
import * as floor from './ops/floor.mjs'
|
||||
|
||||
const math = PocomathInstance.merge('math', numbers, bigints, complex, generic)
|
||||
const math = PocomathInstance.merge(
|
||||
'math', numbers, bigints, complex, generic, floor)
|
||||
|
||||
export default math
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue