typocomath/src/numbers/type.ts

27 lines
713 B
TypeScript

import type { OneOp, ZeroOp, NanOp, ReOp } from '../interfaces/type.js'
export const number_type = {
before: ['Complex'],
test: (n: unknown): n is number => typeof n === 'number',
from: { string: (s: string) => +s }
}
declare module "../interfaces/type" {
interface AssociatedTypes<T> {
numbers: {
type: number
zero: 0
one: 1
nan: typeof NaN
real: number
}
}
}
// I don't like the redundancy of repeating 'zero' and 'ZeroOp', any
// way to eliminate that?
export const zero: ZeroOp<number> = (a) => 0
export const one: OneOp<number> = (a) => 1
export const nan: NanOp<number> = (a) => NaN
export const re: ReOp<number> = (a) => a