typocomath/src/interfaces/arithmetic.ts

26 lines
1.2 KiB
TypeScript

import type {Complex} from '../Complex/type.js'
import type {RealType, WithConstants, NaNType} from './type.js'
// Note: right now I've added an 'Op' suddix,
// so it is clear that the type holds the function type of an operation
// This is not necessary though, it is just a naming convention.
export type AddOp<T> = {op?: 'add', (a: T, b: T): T}
export type AddRealOp<T> = {op?: 'addReal', (a: T, b: RealType<T>): T}
export type UnaryMinusOp<T> = {op?: 'unaryMinus', (a: T): T}
export type ConjOp<T> = {op?: 'conj', (a: T): T}
export type SubtractOp<T> = {op?: 'subtract', (a: T, b: T): T}
export type MultiplyOp<T> = {op?: 'multiply', (a: T, b: T): T}
export type AbsquareOp<T> = {op?: 'absquare', (a: T): RealType<T>}
export type ReciprocalOp<T> = {op?: 'reciprocal', (a: T): T}
export type DivideOp<T> = {op?: 'divide', (a: T, b: T): T}
export type DivideByRealOp<T> = {op?: 'divideByReal', (a: T, b: RealType<T>): T}
export type ConservativeSqrtOp<T> = {op?: 'conservativeSqrt', (a: T): T}
export type SqrtOp<T> = {
op?: 'sqrt',
(a: T): T extends Complex<infer R>
? Complex<WithConstants<R> | NaNType<WithConstants<R>>>
: T | Complex<T>
}
export type SquareOp<T> = {op?: 'square', (z: T): T}