1 | import type {NumberAbsolute, BuildTuple} from './internal';
|
2 | import type {IsEqual} from './is-equal';
|
3 | import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
|
4 | import type {LessThan} from './less-than';
|
5 | import type {Sum} from './sum';
|
6 | import type {And} from './and';
|
7 | import type {Or} from './or';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | export type Subtract<A extends number, B extends number> = number extends A | B
|
40 | ? number
|
41 | : [
|
42 | IsEqual<A, PositiveInfinity>, IsEqual<A, NegativeInfinity>,
|
43 | IsEqual<B, PositiveInfinity>, IsEqual<B, NegativeInfinity>,
|
44 | ] extends infer R extends [boolean, boolean, boolean, boolean]
|
45 | ? Or<
|
46 | And<IsEqual<R[0], true>, IsEqual<R[2], false>>,
|
47 | And<IsEqual<R[3], true>, IsEqual<R[1], false>>
|
48 | > extends true
|
49 | ? PositiveInfinity
|
50 | : Or<
|
51 | And<IsEqual<R[1], true>, IsEqual<R[3], false>>,
|
52 | And<IsEqual<R[2], true>, IsEqual<R[0], false>>
|
53 | > extends true
|
54 | ? NegativeInfinity
|
55 | : true extends R[number]
|
56 | ? number
|
57 | : [IsNegative<A>, IsNegative<B>] extends infer R
|
58 | ? [false, false] extends R
|
59 | ? BuildTuple<A> extends infer R
|
60 | ? R extends [...BuildTuple<B>, ...infer R]
|
61 | ? R['length']
|
62 | : number
|
63 | : never
|
64 | : LessThan<A, B> extends true
|
65 | ? number
|
66 | : [false, true] extends R
|
67 | ? Sum<A, NumberAbsolute<B>>
|
68 | : Subtract<NumberAbsolute<B>, NumberAbsolute<A>>
|
69 | : never
|
70 | : never;
|