Compare commits

..

No commits in common. "0ebaaf35eee8a67c97a442f52be17e777386278b" and "ce974e2a99b8f60b96b1a7e29cbb847f7992c840" have entirely different histories.

5 changed files with 26 additions and 44 deletions

View file

@ -7,7 +7,7 @@
test: 'echo "Error: no test specified" && exit 1', test: 'echo "Error: no test specified" && exit 1',
build: 'mkdirp build && cpy etc/package.json build --flat && tsc', build: 'mkdirp build && cpy etc/package.json build --flat && tsc',
start: 'node build', start: 'node build',
go: 'pnpm --sequential "/clean|build|start/"', go: 'pnpm --sequential "/build|start/"',
clean: 'del-cli build', clean: 'del-cli build',
}, },
packageManager: 'pnpm', packageManager: 'pnpm',
@ -28,7 +28,7 @@
'del-cli': '5.1.0', 'del-cli': '5.1.0',
mkdirp: '3.0.1', mkdirp: '3.0.1',
'source-map': '^0.7.4', 'source-map': '^0.7.4',
'ts-macros': 'github:GoogleFeud/ts-macros', 'ts-macros': '^2.4.1',
'ts-patch': '^3.0.2', 'ts-patch': '^3.0.2',
typescript: '^5.1.6', typescript: '^5.1.6',
}, },

23
pnpm-lock.yaml generated
View file

@ -21,8 +21,8 @@ devDependencies:
specifier: ^0.7.4 specifier: ^0.7.4
version: 0.7.4 version: 0.7.4
ts-macros: ts-macros:
specifier: github:GoogleFeud/ts-macros specifier: ^2.4.1
version: github.com/GoogleFeud/ts-macros/4f8c22db77e3b5840e3a2f285e30436f71c27e15(typescript@5.1.6) version: 2.4.1(typescript@5.1.6)
ts-patch: ts-patch:
specifier: ^3.0.2 specifier: ^3.0.2
version: 3.0.2 version: 3.0.2
@ -843,6 +843,14 @@ packages:
engines: {node: '>=12'} engines: {node: '>=12'}
dev: true dev: true
/ts-macros@2.4.1(typescript@5.1.6):
resolution: {integrity: sha512-DmrftFZ5pgM7dw8ySYcd90wGEfjp7yx9MFw/YyJHNdwKYdUb//lcy/XI/Lvg3LbrGIbjBMEj1rzuc5Kfkzvafg==}
peerDependencies:
typescript: 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x
dependencies:
typescript: 5.1.6
dev: true
/ts-patch@3.0.2: /ts-patch@3.0.2:
resolution: {integrity: sha512-iTg8euqiNsNM1VDfOsVIsP0bM4kAVXU38n7TGQSkky7YQX/syh6sDPIRkvSS0HjT8ZOr0pq1h+5Le6jdB3hiJQ==} resolution: {integrity: sha512-iTg8euqiNsNM1VDfOsVIsP0bM4kAVXU38n7TGQSkky7YQX/syh6sDPIRkvSS0HjT8ZOr0pq1h+5Le6jdB3hiJQ==}
hasBin: true hasBin: true
@ -897,14 +905,3 @@ packages:
resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==} resolution: {integrity: sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==}
engines: {node: '>=10'} engines: {node: '>=10'}
dev: true dev: true
github.com/GoogleFeud/ts-macros/4f8c22db77e3b5840e3a2f285e30436f71c27e15(typescript@5.1.6):
resolution: {tarball: https://codeload.github.com/GoogleFeud/ts-macros/tar.gz/4f8c22db77e3b5840e3a2f285e30436f71c27e15}
id: github.com/GoogleFeud/ts-macros/4f8c22db77e3b5840e3a2f285e30436f71c27e15
name: ts-macros
version: 2.4.2
peerDependencies:
typescript: 4.7.x || 4.8.x || 4.9.x || 5.0.x || 5.1.x
dependencies:
typescript: 5.1.6
dev: true

View file

@ -8,12 +8,6 @@ import {absquare as absquare_complex} from './Complex/arithmetic.js'
const mockRealAdd = (a: number, b: number) => a+b const mockRealAdd = (a: number, b: number) => a+b
const mockComplexAbsquare = (z: Complex<number>) => z.re*z.re + z.im*z.im const mockComplexAbsquare = (z: Complex<number>) => 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({ const quatAbsquare = absquare_complex({
add: mockRealAdd, add: mockRealAdd,
@ -22,16 +16,9 @@ const quatAbsquare = absquare_complex({
const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}}) const myabs = quatAbsquare({re: {re: 0, im: 1}, im: {re:2, im: 3}})
const typeTest: typeof myabs = 7 // check myabs is just a number const typeTest: typeof myabs = 7 // check myabs is just a number
console.log('Result is myabs=', myabs)
const sqrt = Specifications.numbers.sqrt({ console.log('Result is', myabs)
config,
complex: mockComplex
})
console.log('Result of sqrt(16)=', sqrt(16))
console.log('Result of sqrt(-4)=', sqrt(-4))
// Check type of the generic square implementation // Check type of the generic square implementation
console.log('Type of sqrt (number) is', Specifications.numbers.sqrt.reflectedType)
console.log('Type of square is', Specifications.generic.square.reflectedType) console.log('Type of square is', Specifications.generic.square.reflectedType)
console.log('Type of complex square root is', Specifications.complex.sqrt.reflectedType) console.log('Type of complex square root is', Specifications.complex.sqrt.reflectedType)

View file

@ -84,5 +84,5 @@ export type AliasOf<Name extends string, T> = T & {aliasOf?: Name}
// For defining implementations with type reflection // For defining implementations with type reflection
export function $implement<Impl>(name: string, expr: Impl) { export function $implement<Impl>(name: string, expr: Impl) {
$$define!(name, expr, false, true); // Final `true` is export $$define!(name, expr, false, true); // Final `true` is export
$$ident!(name).reflectedType = $$typeToString!<Impl>(true, false, true); $$ident!(name).reflectedType = $$typeToString!<Impl>();
} }

View file

@ -1,6 +1,5 @@
import type {configDependency} from '../core/Config.js' import type {configDependency} from '../core/Config.js'
import type {Dependencies, Signature} from '../interfaces/type.js' import type {Dependencies, Signature} from '../interfaces/type.js'
import { $implement } from '../interfaces/type.js'
export const add: Signature<'add', number> = (a, b) => a + b export const add: Signature<'add', number> = (a, b) => a + b
export const unaryMinus: Signature<'unaryMinus', number> = a => -a export const unaryMinus: Signature<'unaryMinus', number> = a => -a
@ -14,14 +13,13 @@ export const divide: Signature<'divide', number> = (a, b) => a / b
const basicSqrt = a => isNaN(a) ? NaN : Math.sqrt(a) const basicSqrt = a => isNaN(a) ? NaN : Math.sqrt(a)
export const conservativeSqrt: Signature<'conservativeSqrt', number> = basicSqrt export const conservativeSqrt: Signature<'conservativeSqrt', number> = basicSqrt
$implement!('sqrt', export const sqrt =
(dep: configDependency & Dependencies<'complex', number>): Signature<'sqrt', number> => { (dep: configDependency & Dependencies<'complex', number>):
if (dep.config.predictable || !dep.complex) { Signature<'sqrt', number> => {
return basicSqrt if (dep.config.predictable || !dep.complex) return basicSqrt
}
return a => { return a => {
if (isNaN(a)) return NaN if (isNaN(a)) return NaN
if (a >= 0) return Math.sqrt(a) if (a >= 0) return Math.sqrt(a)
return dep.complex(0, Math.sqrt(unaryMinus(a))) return dep.complex(0, Math.sqrt(unaryMinus(a)))
} }
}) }