import {inspect} from 'node:util' import {Dispatcher} from './core/Dispatcher.js' import * as Specifications from './all.js' export default new Dispatcher(Specifications) import {Complex} from './Complex/type.js' import {absquare as absquare_complex} from './Complex/arithmetic.js' import {parseReflectedType} from './core/parseReflectedType.js' const mockRealAdd = (a: number, b: number) => a+b const mockComplexAbsquare = (z: Complex) => z.re*z.re + z.im*z.im const mockComplex = (re: number, im: number) => ({ re, im }) const config = { predictable: false, epsilon: 1e-14 } const quatAbsquare = absquare_complex({ add: mockRealAdd, absquare: mockComplexAbsquare }) const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}}) const typeTest: typeof myabs = 7 // check myabs is just a number 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 })) 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 }))