import type { ToString, Digit, DigitNumber, ToDigitNumber, Sign, Num } from "./utils"; import { Equal as _Equal } from "../../helpers"; export type CompareLength = T["length"] extends U["length"] ? 1 : 0; export type DigitCompareTable = [ [ 0, -1, -1, -1, -1, -1, -1, -1, -1, -1 ], [ 1, 0, -1, -1, -1, -1, -1, -1, -1, -1 ], [ 1, 1, 0, -1, -1, -1, -1, -1, -1, -1 ], [ 1, 1, 1, 0, -1, -1, -1, -1, -1, -1 ], [ 1, 1, 1, 1, 0, -1, -1, -1, -1, -1 ], [ 1, 1, 1, 1, 1, 0, -1, -1, -1, -1 ], [ 1, 1, 1, 1, 1, 1, 0, -1, -1, -1 ], [ 1, 1, 1, 1, 1, 1, 1, 0, -1, -1 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 0, -1 ], [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 ] ]; export type DigitCompare = DigitCompareTable[D1][D2]; export type CompareDigitsWithEqualLength = [T, U] extends [ [ infer N1 extends Digit, ...infer R1 extends Digit[] ], [ infer N2 extends Digit, ...infer R2 extends Digit[] ] ] ? DigitCompare extends 0 ? CompareDigitsWithEqualLength : DigitCompare : 0; export type CompareDigits = CompareLength extends 1 ? CompareDigitsWithEqualLength : keyof U extends keyof T ? 1 : -1; export type CompareDigitNumbers = Sign extends Sign ? Sign extends "" ? CompareDigits, Num> : CompareDigits, Num> : Sign extends "-" ? -1 : 1; /** * Compare two numbers * @param T - First number * @param U - Second number * @returns 0 if T = U, 1 if T > U, -1 if T < U */ export type Compare = _Equal extends true ? 0 : CompareDigitNumbers>, ToDigitNumber>>; export type LessThan = Compare extends -1 ? true : false; export type GreaterThan = Compare extends 1 ? true : false; export type Equal = _Equal; export type NotEqual = _Equal extends true ? false : true; export type LessThanOrEqual = Compare extends -1 | 0 ? true : false; export type GreaterThanOrEqual = Compare extends 1 | 0 ? true : false; export type Max = Compare extends 1 | 0 ? T : U; export type Min = Compare extends 1 | 0 ? U : T;