fix and test absquare for quaternion
This commit is contained in:
parent
60ce6212b4
commit
a5848125e4
@ -56,10 +56,10 @@ export const multiply =
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const absquare =
|
export const absquare =
|
||||||
<T>(dep: {
|
<T, U>(dep: {
|
||||||
add: FnAdd<T>,
|
add: FnAdd<U>,
|
||||||
absquare: FnAbsSquare<T, T>
|
absquare: FnAbsSquare<T, U>
|
||||||
}): FnAbsSquare<Complex<T>, T> =>
|
}): FnAbsSquare<Complex<T>, U> =>
|
||||||
(z) => dep.add(dep.absquare(z.re), dep.absquare(z.im))
|
(z) => dep.add(dep.absquare(z.re), dep.absquare(z.im))
|
||||||
|
|
||||||
export const divideByReal =
|
export const divideByReal =
|
||||||
|
16
src/index.ts
16
src/index.ts
@ -2,3 +2,19 @@ import {Dispatcher} from './core/Dispatcher.js'
|
|||||||
import * as Specifications from './all.js'
|
import * as Specifications from './all.js'
|
||||||
|
|
||||||
export default new Dispatcher(Specifications)
|
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<number>) => 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)
|
||||||
|
Loading…
Reference in New Issue
Block a user