fix and test absquare for quaternion
This commit is contained in:
parent
04024a2a8d
commit
40c7cd36af
3
.gitignore
vendored
3
.gitignore
vendored
@ -129,6 +129,9 @@ dist
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
.vscode-test
|
||||
|
||||
# WebStorm
|
||||
.idea
|
||||
|
||||
# yarn v2
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
|
@ -51,11 +51,11 @@ export const multiply =
|
||||
}
|
||||
|
||||
export const absquare =
|
||||
<T>(dep: {
|
||||
add: (a: T, b: T) => T,
|
||||
absquare: (z: T) => T
|
||||
<T, U>(dep: {
|
||||
add: (a: U, b: U) => U,
|
||||
absquare: (z: T) => U
|
||||
}) =>
|
||||
(z: Complex<T>): T => dep.add(dep.absquare(z.re), dep.absquare(z.im))
|
||||
(z: Complex<T>): U => dep.add(dep.absquare(z.re), dep.absquare(z.im))
|
||||
|
||||
export const divideByReal =
|
||||
<T>(dep: {
|
||||
|
19
src/index.ts
19
src/index.ts
@ -2,3 +2,22 @@ import {Dispatcher} from './core/Dispatcher.js'
|
||||
import * as Specifications from './all.js'
|
||||
|
||||
export default new Dispatcher(Specifications)
|
||||
|
||||
|
||||
// Test https://github.com/josdejong/pocomath/issues/1#issuecomment-1364056151
|
||||
|
||||
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