22 lines
684 B
TypeScript
22 lines
684 B
TypeScript
import {Complex} from './type.js'
|
|
import {Dependency, ImpType} from '../core/Dispatcher.js'
|
|
|
|
type ComplexPredicate<T> = T extends Complex<any> ? (a: T) => boolean : never
|
|
|
|
declare module "./type" {
|
|
interface ComplexImpTypes<T> {
|
|
isReal: ComplexPredicate<T>
|
|
isSquare: ComplexPredicate<T>
|
|
}
|
|
}
|
|
|
|
export const isReal =
|
|
<T>(dep: Dependency<'equal', [T,T]>
|
|
& Dependency<'add', [T,T]>
|
|
& Dependency<'isReal', [T]>
|
|
): ImpType<'isReal', [Complex<T>]> =>
|
|
z => dep.isReal(z.re) && dep.equal(z.re, dep.add(z.re, z.im))
|
|
|
|
export const isSquare: ImpType<'isSquare', [Complex<any>]> =
|
|
z => true // FIXME: not correct for Complex<bigint> once we get there
|