You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
enumComparison{Greater,Equal,Lower,}typeComparator<Xextendsnumber,Yextendsnumber>={'<': Comparison.Lower,'=': Comparison.Equal,'>': Comparison.Greater}[CompareNumbers<`${X}`, `${Y}`>]// Type to compare two numeric types X and Y and determine their relational order as '<', '=', or '>'.typeCompareNumbers<Xextendsstring,Yextendsstring>= `${X}${Y}` extends `-${infer A}-${infer B}` ? CompareNumbers<B,A>// Handles comparison when both numbers are negative, invert the comparison order to compare their positive counterparts
: Xextends `-${any}` ? '<'// If X is negative and Y is not Y is greater
: Yextends `-${any}` ? '>'// If Y is negative and X is not X is greater
: `${X} ${Y}` extends `${infer A}e+${infer E} ${infer B}e+${infer F}` ? CompareInteger<E,F>extends'=' ? CompareNumbers<A,B> : CompareInteger<E,F>
: Xextends `${any}e+${any}` ? '>'
: Yextends `${any}e+${any}` ? '<'
: `${X} ${Y}` extends `${infer A}e-${infer E} ${infer B}e-${infer F}` ? CompareInteger<F,E>extends'=' ? CompareNumbers<A,B> : CompareInteger<F,E>
: Xextends `${any}e-${any}` ? '<'
: Yextends `${any}e-${any}` ? '>'
: `${X} ${Y}` extends `${infer A}.${infer C} ${infer B}.${infer D}` ? CompareInteger<A,B>extends'=' ? CompareFractional<C,D> : CompareInteger<A,B>
: Xextends `${infer A}.${any}` ? CompareInteger<A,Y>extends'=' ? '>' : CompareInteger<A,Y>
: Yextends `${infer B}.${any}` ? CompareInteger<X,B>extends'=' ? '<' : CompareInteger<X,B>
: CompareInteger<X,Y>// Recursive type to compare integer strings and determine their order.typeCompareInteger<Xextendsstring,Yextendsstring,PreviousComparisonextends'<'|'='|'>'='='>=XextendsY ? PreviousComparison// If both strings are equal, return the previous comparison result
: `${X} ${Y}` extends `${infer A}${infer C} ${infer B}${infer D}`
? CompareInteger<C,D,PreviousComparisonextends'<'|'>' ? PreviousComparison// If difference has been found, Carry forward the first difference
: AextendsB ? '='// If current digits are the same, skip to next
: '0123456789'extends `${any}${A}${any}${B}${any}` ? '<' : '>'>// Compare digits lexicographically
: Xextends'' ? '<' : '>'// longer is greatertypeCompareFractional<Xextendsstring,Yextendsstring>= `${X} ${Y}` extends `${infer A}${infer C} ${infer B}${infer D}`
? AextendsB ? CompareFractional<C,D>// If current digits are the same, skip to next
: '0123456789'extends `${any}${A}${any}${B}${any}` ? '<' : '>'// Compare digits lexicographically
: Xextends'' ? '<' : '>'// longer is greater
Playground
The text was updated successfully, but these errors were encountered: