This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ShiftLeft<T extends Byte> = T extends [ | |
infer U extends Bit, | |
...infer R extends Bit[] | |
] | |
? [...R, Zero] | |
: never; | |
type ShiftRight<T extends Byte> = T extends [ | |
...infer U extends Bit[], | |
infer R extends Bit | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PartialByteNot<T extends Bit[]> = T extends [ | |
infer U extends Bit, | |
...infer R extends Bit[] | |
] | |
? [BitNot<U>, ...PartialByteNot<R>] | |
: []; | |
type ByteNot<T extends Byte> = T extends [ | |
infer U extends Bit, | |
...infer R extends Bit[] | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PartialByteXOR<LHS extends Bit[], RHS extends Bit[]> = LHS extends [ | |
infer LHSU extends Bit, | |
...infer LHSR extends Bit[] | |
] | |
? RHS extends [infer RHSU extends Bit, ...infer RHSR extends Bit[]] | |
? [BitXor<LHSU, RHSU>, ...PartialByteXOR<LHSR, RHSR>] | |
: [] | |
: []; | |
type ByteXOR<LHS extends Byte, RHS extends Byte> = LHS extends [ | |
infer LHSU extends Bit, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PartialAddOne<T extends Bit[]> = T extends [ | |
...infer U extends Bit[], | |
infer R extends Bit | |
] | |
? R extends One | |
? [...PartialAddOne<U>, Zero] | |
: [...U, One] | |
: []; | |
type AddOne<T extends Byte> = T extends [ | |
...infer U extends Bit[], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PartialAdd< | |
LHS extends Bit[], | |
RHS extends Bit[], | |
CF extends CarryFlag = Zero | |
> = LHS extends [...infer LHSU extends Bit[], infer LHSR extends Bit] | |
? RHS extends [...infer RHSU extends Bit[], infer RHSR extends Bit] | |
? [ | |
...PartialAdd<LHSU, RHSU, AddBitsWithCarry<LHSR, RHSR, CF>["cf"]>, | |
AddBitsWithCarry<LHSR, RHSR, CF>["value"] | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LTPartial<LHS extends Bit[], RHS extends Bit[]> = LHS extends [infer LHSU extends Bit, ...infer LHSR extends Bit[]] | |
? RHS extends [infer RHSU extends Bit, ...infer RHSR extends Bit[]] | |
? true extends BitLTB<LHSU, RHSU> | |
? true | |
: false extends BitLTB<LHSU, RHSU> | |
? false | |
: "undecided" extends BitLTB<LHSU, RHSU> | |
? LTPartial<LHSR, RHSR> | |
: false | |
: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FIBONACCI< | |
C extends Byte, | |
A extends Byte = ONE_BYTE, | |
B extends Byte = ONE_BYTE | |
> = ONE_BYTE extends C | |
? A | |
: AddOne<ONE_BYTE> extends C | |
? A | |
: FIBONACCI<SubtractOne<C>, Add<A, B>, A>; |
OlderNewer