1 | import type {NumberAbsolute, BuildTuple, TupleMax, TupleMin} from './internal';
|
2 | import type {IsEqual} from './is-equal';
|
3 | import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
|
4 | import type {Subtract} from './subtract';
|
5 | import type {And} from './and';
|
6 | import type {Or} from './or';
|
7 |
|
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 Sum<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[3], false>>,
|
47 | And<IsEqual<R[2], true>, IsEqual<R[1], false>>
|
48 | > extends true
|
49 | ? PositiveInfinity
|
50 | : Or<
|
51 | And<IsEqual<R[1], true>, IsEqual<R[2], false>>,
|
52 | And<IsEqual<R[3], 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>, ...BuildTuple<B>]['length']
|
60 | : [true, true] extends R
|
61 | ? number
|
62 | : TupleMax<[NumberAbsolute<A>, NumberAbsolute<B>]> extends infer Max_
|
63 | ? TupleMin<[NumberAbsolute<A>, NumberAbsolute<B>]> extends infer Min_ extends number
|
64 | ? Max_ extends A | B
|
65 | ? Subtract<Max_, Min_>
|
66 | : number
|
67 | : never
|
68 | : never
|
69 | : never) & number
|
70 | : never;
|