2023-10-17 22:02:18 +00:00
|
|
|
import {inspect} from 'node:util'
|
2022-12-07 01:21:05 +00:00
|
|
|
import {Dispatcher} from './core/Dispatcher.js'
|
|
|
|
import * as Specifications from './all.js'
|
2022-12-06 17:10:18 +00:00
|
|
|
|
|
|
|
export default new Dispatcher(Specifications)
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
import {Complex} from './Complex/type.js'
|
|
|
|
import {absquare as absquare_complex} from './Complex/arithmetic.js'
|
2023-10-17 22:02:18 +00:00
|
|
|
import {parseReflectedType} from './core/parseReflectedType.js'
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
const mockRealAdd = (a: number, b: number) => a+b
|
|
|
|
const mockComplexAbsquare = (z: Complex<number>) => z.re*z.re + z.im*z.im
|
2023-10-17 22:02:18 +00:00
|
|
|
const mockComplex = (re: number, im: number) => ({ re, im })
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
predictable: false,
|
|
|
|
epsilon: 1e-14
|
|
|
|
}
|
2023-01-22 01:34:57 +00:00
|
|
|
|
|
|
|
const quatAbsquare = absquare_complex({
|
2023-10-17 22:02:18 +00:00
|
|
|
add: mockRealAdd,
|
|
|
|
absquare: mockComplexAbsquare
|
2023-01-22 01:34:57 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}})
|
|
|
|
const typeTest: typeof myabs = 7 // check myabs is just a number
|
2023-10-17 22:02:18 +00:00
|
|
|
console.log('Result is myabs=', myabs)
|
|
|
|
|
|
|
|
const sqrt = Specifications.numbers.sqrt({
|
|
|
|
config,
|
|
|
|
complex: mockComplex
|
|
|
|
})
|
|
|
|
console.log('Result of sqrt(16)=', sqrt(16))
|
|
|
|
console.log('Result of sqrt(-4)=', sqrt(-4))
|
|
|
|
|
|
|
|
console.log()
|
|
|
|
console.log('1) NUMBER SQRT')
|
|
|
|
console.log(`1.1) REFLECTED TYPE: "${Specifications.numbers.sqrt.reflectedType}"`)
|
|
|
|
console.log(
|
|
|
|
'1.2) PARSED TYPE:',
|
|
|
|
inspect(
|
|
|
|
parseReflectedType('sqrt', Specifications.numbers.sqrt.reflectedType),
|
|
|
|
{ depth: null, colors: true }))
|
|
|
|
|
|
|
|
console.log()
|
|
|
|
console.log('2) GENERIC SQUARE')
|
|
|
|
console.log(`1.1) REFLECTED TYPE: "${Specifications.generic.square.reflectedType}"`)
|
|
|
|
console.log('2.2) PARSED TYPE:', inspect(parseReflectedType('square', Specifications.generic.square.reflectedType), { depth: null, colors: true }))
|
2023-01-22 01:34:57 +00:00
|
|
|
|
2023-10-17 22:02:18 +00:00
|
|
|
console.log()
|
|
|
|
console.log('3) COMPLEX SQRT')
|
|
|
|
console.log(`1.1) REFLECTED TYPE: "${Specifications.complex.sqrt.reflectedType}"`)
|
|
|
|
console.log('3.2) PARSED TYPE:', inspect(parseReflectedType('sqrt', Specifications.complex.sqrt.reflectedType), { depth: null, colors: true }))
|