From a5848125e45f208b6a6a3f435e81f7ea15407f03 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Fri, 23 Dec 2022 17:18:24 +0100 Subject: [PATCH] fix and test absquare for quaternion --- src/Complex/arithmetic.ts | 8 ++++---- src/index.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Complex/arithmetic.ts b/src/Complex/arithmetic.ts index 0987779..a9d0d42 100644 --- a/src/Complex/arithmetic.ts +++ b/src/Complex/arithmetic.ts @@ -56,10 +56,10 @@ export const multiply = } export const absquare = - (dep: { - add: FnAdd, - absquare: FnAbsSquare - }): FnAbsSquare, T> => + (dep: { + add: FnAdd, + absquare: FnAbsSquare + }): FnAbsSquare, U> => (z) => dep.add(dep.absquare(z.re), dep.absquare(z.im)) export const divideByReal = diff --git a/src/index.ts b/src/index.ts index bb83486..297b271 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,3 +2,19 @@ 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' + +const mockRealAdd = (a: number, b: number) => a+b +const mockComplexAbsquare = (z: Complex) => z.re*z.re + z.im*z.im + +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)