diff options
author | Araq <rumpf_a@web.de> | 2012-07-14 14:03:13 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-07-14 14:03:13 +0200 |
commit | b4084df434dc22d61960bcd6374d34af27bba888 (patch) | |
tree | de6689dc1e0465117345f5d0d3bc6b03817cb8a2 /lib/core | |
parent | 100596119202e7a0d543be17e5c08372fe4238cd (diff) | |
download | Nim-b4084df434dc22d61960bcd6374d34af27bba888.tar.gz |
improved unsigned support
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/unsigned.nim | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/core/unsigned.nim b/lib/core/unsigned.nim new file mode 100644 index 000000000..63183f56a --- /dev/null +++ b/lib/core/unsigned.nim @@ -0,0 +1,59 @@ +# +# +# Nimrod's Runtime Library +# (c) Copyright 2012 Andreas Rumpf +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module implements basic arithmetic operators for unsigned integers. +## To discourage users from using ``unsigned``, it's not part of ``system``, +## but an extra import. + +type + SomeUInt = uint|uint8|uint16|uint32|uint64 + +proc `not`*[T: SomeUInt](x: T): T {.magic: "BitnotI", noSideEffect.} + ## computes the `bitwise complement` of the integer `x`. + +proc `shr`*[T: SomeUInt](x, y: T): T {.magic: "ShrI", noSideEffect.} + ## computes the `shift right` operation of `x` and `y`. + +proc `shl`*[T: SomeUInt](x, y: T): T {.magic: "ShlI", noSideEffect.} + ## computes the `shift left` operation of `x` and `y`. + +proc `and`*[T: SomeUInt](x, y: T): T {.magic: "BitandI", noSideEffect.} + ## computes the `bitwise and` of numbers `x` and `y`. + +proc `or`*[T: SomeUInt](x, y: T): T {.magic: "BitorI", noSideEffect.} + ## computes the `bitwise or` of numbers `x` and `y`. + +proc `xor`*[T: SomeUInt](x, y: T): T {.magic: "BitxorI", noSideEffect.} + ## computes the `bitwise xor` of numbers `x` and `y`. + +proc `==`*[T: SomeUInt](x, y: T): bool {.magic: "EqI", noSideEffect.} + ## Compares two unsigned integers for equality. + +proc `+`*[T: SomeUInt](x, y: T): T {.magic: "AddU", noSideEffect.} + ## Binary `+` operator for unsigned integers. + +proc `-`*[T: SomeUInt](x, y: T): T {.magic: "SubU", noSideEffect.} + ## Binary `-` operator for unsigned integers. + +proc `*`*[T: SomeUInt](x, y: T): T {.magic: "MulU", noSideEffect.} + ## Binary `*` operator for unsigned integers. + +proc `div`*[T: SomeUInt](x, y: T): T {.magic: "DivU", noSideEffect.} + ## computes the integer division. This is roughly the same as + ## ``floor(x/y)``. + +proc `mod`*[T: SomeUInt](x, y: T): T {.magic: "ModU", noSideEffect.} + ## computes the integer modulo operation. This is the same as + ## ``x - (x div y) * y``. + +proc `<=`*[T: SomeUInt](x, y: SomeUInt): bool {.magic: "LeU", noSideEffect.} + ## Returns true iff ``x <= y``. + +proc `<`*[T: SomeUInt](x, y: T): bool {.magic: "LtU", noSideEffect.} + ## Returns true iff ``unsigned(x) < unsigned(y)``. |