From 11a908fd405a0ac0f136477f5817b2fd74e195f3 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 5 Mar 2015 17:28:11 +0100 Subject: [PATCH 1/4] Move unsigned int operations to system module This should lead to less confusion because uint numbers and literals seem to work, but operators are just missing. --- lib/core/unsigned.nim | 52 +++++-------------------------------------- lib/system.nim | 45 ++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/lib/core/unsigned.nim b/lib/core/unsigned.nim index 20fcd03aa5..18bb92ee37 100644 --- a/lib/core/unsigned.nim +++ b/lib/core/unsigned.nim @@ -7,51 +7,9 @@ # 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. - -proc `not`*[T: SomeUnsignedInt](x: T): T {.magic: "BitnotI", noSideEffect.} - ## computes the `bitwise complement` of the integer `x`. - -proc `shr`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ShrI", noSideEffect.} - ## computes the `shift right` operation of `x` and `y`. - -proc `shl`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ShlI", noSideEffect.} - ## computes the `shift left` operation of `x` and `y`. - -proc `and`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitandI", noSideEffect.} - ## computes the `bitwise and` of numbers `x` and `y`. - -proc `or`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitorI", noSideEffect.} - ## computes the `bitwise or` of numbers `x` and `y`. - -proc `xor`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitxorI", noSideEffect.} - ## computes the `bitwise xor` of numbers `x` and `y`. - -proc `==`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "EqI", noSideEffect.} - ## Compares two unsigned integers for equality. - -proc `+`*[T: SomeUnsignedInt](x, y: T): T {.magic: "AddU", noSideEffect.} - ## Binary `+` operator for unsigned integers. - -proc `-`*[T: SomeUnsignedInt](x, y: T): T {.magic: "SubU", noSideEffect.} - ## Binary `-` operator for unsigned integers. - -proc `*`*[T: SomeUnsignedInt](x, y: T): T {.magic: "MulU", noSideEffect.} - ## Binary `*` operator for unsigned integers. - -proc `div`*[T: SomeUnsignedInt](x, y: T): T {.magic: "DivU", noSideEffect.} - ## computes the integer division. This is roughly the same as - ## ``floor(x/y)``. - -proc `mod`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ModU", noSideEffect.} - ## computes the integer modulo operation. This is the same as - ## ``x - (x div y) * y``. - -proc `<=`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "LeU", noSideEffect.} - ## Returns true iff ``x <= y``. - -proc `<`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "LtU", noSideEffect.} - ## Returns true iff ``unsigned(x) < unsigned(y)``. +## **Warning:** Since version 0.10.4 this module is deprecated. +## +## This module implemented basic arithmetic operators for unsigned integers. +## These operators are now available in the ``system`` module directly. +{.deprecated.} diff --git a/lib/system.nim b/lib/system.nim index e11722ae06..136c358201 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -888,9 +888,52 @@ proc `<%` *(x, y: int64): bool {.magic: "LtU64", noSideEffect.} ## treats `x` and `y` as unsigned and compares them. ## Returns true iff ``unsigned(x) < unsigned(y)``. +# unsigned integer operations: +proc `not`*[T: SomeUnsignedInt](x: T): T {.magic: "BitnotI", noSideEffect.} + ## computes the `bitwise complement` of the integer `x`. + +proc `shr`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ShrI", noSideEffect.} + ## computes the `shift right` operation of `x` and `y`. + +proc `shl`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ShlI", noSideEffect.} + ## computes the `shift left` operation of `x` and `y`. + +proc `and`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitandI", noSideEffect.} + ## computes the `bitwise and` of numbers `x` and `y`. + +proc `or`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitorI", noSideEffect.} + ## computes the `bitwise or` of numbers `x` and `y`. + +proc `xor`*[T: SomeUnsignedInt](x, y: T): T {.magic: "BitxorI", noSideEffect.} + ## computes the `bitwise xor` of numbers `x` and `y`. + +proc `==`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "EqI", noSideEffect.} + ## Compares two unsigned integers for equality. + +proc `+`*[T: SomeUnsignedInt](x, y: T): T {.magic: "AddU", noSideEffect.} + ## Binary `+` operator for unsigned integers. + +proc `-`*[T: SomeUnsignedInt](x, y: T): T {.magic: "SubU", noSideEffect.} + ## Binary `-` operator for unsigned integers. + +proc `*`*[T: SomeUnsignedInt](x, y: T): T {.magic: "MulU", noSideEffect.} + ## Binary `*` operator for unsigned integers. + +proc `div`*[T: SomeUnsignedInt](x, y: T): T {.magic: "DivU", noSideEffect.} + ## computes the integer division. This is roughly the same as + ## ``floor(x/y)``. + +proc `mod`*[T: SomeUnsignedInt](x, y: T): T {.magic: "ModU", noSideEffect.} + ## computes the integer modulo operation. This is the same as + ## ``x - (x div y) * y``. + +proc `<=`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "LeU", noSideEffect.} + ## Returns true iff ``x <= y``. + +proc `<`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "LtU", noSideEffect.} + ## Returns true iff ``unsigned(x) < unsigned(y)``. # floating point operations: - proc `+` *(x: float32): float32 {.magic: "UnaryPlusF64", noSideEffect.} proc `-` *(x: float32): float32 {.magic: "UnaryMinusF64", noSideEffect.} proc `+` *(x, y: float32): float32 {.magic: "AddF64", noSideEffect.} From 6f145230eeb8b8ae5c8c857945443e3a393b20fe Mon Sep 17 00:00:00 2001 From: def Date: Thu, 5 Mar 2015 17:29:47 +0100 Subject: [PATCH 2/4] Remove unsigned from lib.txt --- doc/lib.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/doc/lib.txt b/doc/lib.txt index 14a13c0d24..6a8f32e071 100644 --- a/doc/lib.txt +++ b/doc/lib.txt @@ -35,11 +35,6 @@ Core implicitly by the compiler. Do not import it directly. It relies on compiler magic to work. -* `unsigned `_ - This module implements basic arithmetic operators for unsigned integers. - To discourage users from using unsigned integers, it's not part - of ``system``, but an extra import. - * `threads `_ Nim thread support. **Note**: This is part of the system module. Do not import it explicitly. From ec97195d8f2319fa74f957f1e493034d7f2a0be0 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 5 Mar 2015 17:35:13 +0100 Subject: [PATCH 3/4] Add unsigned exports for backwards-compatibility --- lib/core/unsigned.nim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/core/unsigned.nim b/lib/core/unsigned.nim index 18bb92ee37..fa8bb91c96 100644 --- a/lib/core/unsigned.nim +++ b/lib/core/unsigned.nim @@ -13,3 +13,6 @@ ## These operators are now available in the ``system`` module directly. {.deprecated.} + +export `shr`, `shl`, `and`, `or`, `xor`, `==`, `+`, `-`, `*`, `div`, `mod`, + `<=`, `<` From 2353fe343a11ba3744a11f8a61ec7c224c2f9490 Mon Sep 17 00:00:00 2001 From: def Date: Thu, 2 Jul 2015 12:26:04 +0200 Subject: [PATCH 4/4] Update deprecation notice about unsigned module --- lib/core/unsigned.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/unsigned.nim b/lib/core/unsigned.nim index fa8bb91c96..93a29e1c94 100644 --- a/lib/core/unsigned.nim +++ b/lib/core/unsigned.nim @@ -7,7 +7,7 @@ # distribution, for details about the copyright. # -## **Warning:** Since version 0.10.4 this module is deprecated. +## **Warning:** Since version 0.11.4 this module is deprecated. ## ## This module implemented basic arithmetic operators for unsigned integers. ## These operators are now available in the ``system`` module directly.