Created
April 6, 2018 16:25
-
-
Save mratsim/c9ac14d049222d0c6bce6daa1bfd8fad to your computer and use it in GitHub Desktop.
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
| template defineIntConstructor(typ: typedesc, name: untyped{nkIdent}) = | |
| template name*(a: int64): typ = initInt[typ](a) | |
| template name*(a: cstring): typ = initInt[typ](a) | |
| template `+`*(a: typ, b: int{lit}): typ = a + initInt[typ](b) | |
| template `+`*(a: int{lit}, b: typ): typ = initInt[typ](a) + b | |
| template `-`*(a: typ, b: int{lit}): typ = a - initInt[typ](b) | |
| template `-`*(a: int{lit}, b: typ): typ = initInt[typ](a) - b | |
| defineIntConstructor(Int256, i256) | |
| defineIntConstructor(Int512, i512) | |
| defineIntConstructor(Int1024, i1024) | |
| defineIntConstructor(Int2048, i2048) | |
| template defineUIntConstructor(typ: typedesc, name: untyped{nkIdent}) = | |
| template name*(a: uint64): typ = initUInt[typ](a) | |
| template name*(a: cstring): typ = initInt[typ](a) | |
| template `+`*(a: typ, b: int{lit}): typ = a + initUInt[typ](b) | |
| template `+`*(a: int{lit}, b: typ): typ = initUInt[typ](a) + b | |
| template `-`*(a: typ, b: int{lit}): typ = a - initUInt[typ](b) | |
| template `-`*(a: int{lit}, b: typ): typ = initUInt[typ](a) - b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment