feat(Complex): support division #40
9
src/complex/invert.mjs
Normal file
9
src/complex/invert.mjs
Normal file
@ -0,0 +1,9 @@
|
||||
export * from './Types/Complex.mjs'
|
||||
|
||||
export const invert = {
|
||||
Complex: ({conjugate, absquare, complex, divide}) => z => {
|
||||
const c = conjugate(z)
|
||||
const d = absquare(z)
|
||||
return complex(divide(c.re, d), divide(c.im, d))
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ export {add} from './add.mjs'
|
||||
export {conjugate} from './conjugate.mjs'
|
||||
export {complex} from './complex.mjs'
|
||||
export {gcd} from './gcd.mjs'
|
||||
export {invert} from './invert.mjs'
|
||||
export {isZero} from './isZero.mjs'
|
||||
export {multiply} from './multiply.mjs'
|
||||
export {negate} from './negate.mjs'
|
||||
|
@ -4,6 +4,15 @@ import PocomathInstance from '../../src/core/PocomathInstance.mjs'
|
||||
import * as complexSqrt from '../../src/complex/sqrt.mjs'
|
||||
|
||||
describe('complex', () => {
|
||||
it('supports division', () => {
|
||||
assert.deepStrictEqual(
|
||||
math.divide(math.complex(3,2), math.complex(0,1)),
|
||||
math.complex(2,-3))
|
||||
const reciprocal = math.divide(1, math.complex(1,3))
|
||||
assert.strictEqual(reciprocal.re, 0.1)
|
||||
assert.ok(Math.abs(reciprocal.im + 0.3) < 1e-13)
|
||||
})
|
||||
|
||||
it('supports sqrt', () => {
|
||||
assert.deepStrictEqual(math.sqrt(math.complex(1,0)), 1)
|
||||
assert.deepStrictEqual(
|
||||
|
Loading…
Reference in New Issue
Block a user