make the docs of arithmetics better (#16510)

* fix

* Update lib/system/arithmetics.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Apply suggestions from code review

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* Apply suggestions from code review

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
This commit is contained in:
flywind 2020-12-30 10:30:43 -06:00 • committed by GitHub
commit b42e7c0ef9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,48 +1,44 @@
proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.} proc succ*[T: Ordinal](x: T, y = 1): T {.magic: "Succ", noSideEffect.} =
## Returns the ``y``-th successor (default: 1) of the value ``x``. ## Returns the `y`-th successor (default: 1) of the value `x`.
## ``T`` has to be an `ordinal type <#Ordinal>`_.
## ##
## If such a value does not exist, ``OverflowDefect`` is raised ## If such a value does not exist, `OverflowDefect` is raised
## or a compile time error occurs. ## or a compile time error occurs.
## runnableExamples:
## .. code-block:: Nim assert succ(5) == 6
## let x = 5 assert succ(5, 3) == 8
## echo succ(5) # => 6
## echo succ(5, 3) # => 8
proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.} proc pred*[T: Ordinal](x: T, y = 1): T {.magic: "Pred", noSideEffect.} =
## Returns the ``y``-th predecessor (default: 1) of the value ``x``. ## Returns the `y`-th predecessor (default: 1) of the value `x`.
## ``T`` has to be an `ordinal type <#Ordinal>`_.
## ##
## If such a value does not exist, ``OverflowDefect`` is raised ## If such a value does not exist, `OverflowDefect` is raised
## or a compile time error occurs. ## or a compile time error occurs.
## runnableExamples:
## .. code-block:: Nim assert pred(5) == 4
## let x = 5 assert pred(5, 3) == 2
## echo pred(5) # => 4
## echo pred(5, 3) # => 2
proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.} proc inc*[T: Ordinal](x: var T, y = 1) {.magic: "Inc", noSideEffect.} =
## Increments the ordinal ``x`` by ``y``. ## Increments the ordinal `x` by `y`.
## ##
## If such a value does not exist, ``OverflowDefect`` is raised or a compile ## If such a value does not exist, `OverflowDefect` is raised or a compile
## time error occurs. This is a short notation for: ``x = succ(x, y)``. ## time error occurs. This is a short notation for: `x = succ(x, y)`.
## runnableExamples:
## .. code-block:: Nim var i = 2
## var i = 2 inc(i)
## inc(i) # i <- 3 assert i == 3
## inc(i, 3) # i <- 6 inc(i, 3)
assert i == 6
proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.} proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.} =
## Decrements the ordinal ``x`` by ``y``. ## Decrements the ordinal `x` by `y`.
## ##
## If such a value does not exist, ``OverflowDefect`` is raised or a compile ## If such a value does not exist, `OverflowDefect` is raised or a compile
## time error occurs. This is a short notation for: ``x = pred(x, y)``. ## time error occurs. This is a short notation for: `x = pred(x, y)`.
## runnableExamples:
## .. code-block:: Nim var i = 2
## var i = 2 dec(i)
## dec(i) # i <- 1 assert i == 1
## dec(i, 3) # i <- -2 dec(i, 3)
assert i == -2
@ -51,38 +47,38 @@ proc dec*[T: Ordinal](x: var T, y = 1) {.magic: "Dec", noSideEffect.}
when defined(nimNoZeroExtendMagic): when defined(nimNoZeroExtendMagic):
proc ze*(x: int8): int {.deprecated.} = proc ze*(x: int8): int {.deprecated.} =
## zero extends a smaller integer type to ``int``. This treats `x` as ## zero extends a smaller integer type to `int`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int](uint(cast[uint8](x))) cast[int](uint(cast[uint8](x)))
proc ze*(x: int16): int {.deprecated.} = proc ze*(x: int16): int {.deprecated.} =
## zero extends a smaller integer type to ``int``. This treats `x` as ## zero extends a smaller integer type to `int`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int](uint(cast[uint16](x))) cast[int](uint(cast[uint16](x)))
proc ze64*(x: int8): int64 {.deprecated.} = proc ze64*(x: int8): int64 {.deprecated.} =
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int64](uint64(cast[uint8](x))) cast[int64](uint64(cast[uint8](x)))
proc ze64*(x: int16): int64 {.deprecated.} = proc ze64*(x: int16): int64 {.deprecated.} =
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int64](uint64(cast[uint16](x))) cast[int64](uint64(cast[uint16](x)))
proc ze64*(x: int32): int64 {.deprecated.} = proc ze64*(x: int32): int64 {.deprecated.} =
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int64](uint64(cast[uint32](x))) cast[int64](uint64(cast[uint32](x)))
proc ze64*(x: int): int64 {.deprecated.} = proc ze64*(x: int): int64 {.deprecated.} =
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``. ## unsigned. Does nothing if the size of an `int` is the same as `int64`.
## (This is the case on 64 bit processors.) ## (This is the case on 64 bit processors.)
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int64](uint64(cast[uint](x))) cast[int64](uint64(cast[uint](x)))
@ -94,46 +90,46 @@ when defined(nimNoZeroExtendMagic):
cast[int8](x) cast[int8](x)
proc toU16*(x: int): int16 {.deprecated.} = proc toU16*(x: int): int16 {.deprecated.} =
## treats `x` as unsigned and converts it to an ``int16`` by taking the last ## treats `x` as unsigned and converts it to an `int16` by taking the last
## 16 bits from `x`. ## 16 bits from `x`.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int16](x) cast[int16](x)
proc toU32*(x: int64): int32 {.deprecated.} = proc toU32*(x: int64): int32 {.deprecated.} =
## treats `x` as unsigned and converts it to an ``int32`` by taking the ## treats `x` as unsigned and converts it to an `int32` by taking the
## last 32 bits from `x`. ## last 32 bits from `x`.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
cast[int32](x) cast[int32](x)
elif not defined(js): elif not defined(js):
proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect, deprecated.} proc ze*(x: int8): int {.magic: "Ze8ToI", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int``. This treats `x` as ## zero extends a smaller integer type to `int`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect, deprecated.} proc ze*(x: int16): int {.magic: "Ze16ToI", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int``. This treats `x` as ## zero extends a smaller integer type to `int`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect, deprecated.} proc ze64*(x: int8): int64 {.magic: "Ze8ToI64", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect, deprecated.} proc ze64*(x: int16): int64 {.magic: "Ze16ToI64", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect, deprecated.} proc ze64*(x: int32): int64 {.magic: "Ze32ToI64", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. ## unsigned.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc ze64*(x: int): int64 {.magic: "ZeIToI64", noSideEffect, deprecated.} proc ze64*(x: int): int64 {.magic: "ZeIToI64", noSideEffect, deprecated.}
## zero extends a smaller integer type to ``int64``. This treats `x` as ## zero extends a smaller integer type to `int64`. This treats `x` as
## unsigned. Does nothing if the size of an ``int`` is the same as ``int64``. ## unsigned. Does nothing if the size of an `int` is the same as `int64`.
## (This is the case on 64 bit processors.) ## (This is the case on 64 bit processors.)
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
@ -143,12 +139,12 @@ elif not defined(js):
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect, deprecated.} proc toU16*(x: int): int16 {.magic: "ToU16", noSideEffect, deprecated.}
## treats `x` as unsigned and converts it to an ``int16`` by taking the last ## treats `x` as unsigned and converts it to an `int16` by taking the last
## 16 bits from `x`. ## 16 bits from `x`.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect, deprecated.} proc toU32*(x: int64): int32 {.magic: "ToU32", noSideEffect, deprecated.}
## treats `x` as unsigned and converts it to an ``int32`` by taking the ## treats `x` as unsigned and converts it to an `int32` by taking the
## last 32 bits from `x`. ## last 32 bits from `x`.
## **Deprecated since version 0.19.9**: Use unsigned integers instead. ## **Deprecated since version 0.19.9**: Use unsigned integers instead.
@ -167,20 +163,13 @@ proc `-`*(x: int16): int16 {.magic: "UnaryMinusI", noSideEffect.}
proc `-`*(x: int32): int32 {.magic: "UnaryMinusI", noSideEffect.} proc `-`*(x: int32): int32 {.magic: "UnaryMinusI", noSideEffect.}
proc `-`*(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.} proc `-`*(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.}
proc `not`*(x: int): int {.magic: "BitnotI", noSideEffect.} proc `not`*(x: int): int {.magic: "BitnotI", noSideEffect.} =
## Computes the `bitwise complement` of the integer `x`. ## Computes the `bitwise complement` of the integer `x`.
## runnableExamples:
## .. code-block:: Nim assert not 0'u8 == 255
## var assert not 0'i8 == -1
## a = 0'u8 assert not 1000'u16 == 64535
## b = 0'i8 assert not 1000'i16 == -1001
## c = 1000'u16
## d = 1000'i16
##
## echo not a # => 255
## echo not b # => -1
## echo not c # => 64535
## echo not d # => -1001
proc `not`*(x: int8): int8 {.magic: "BitnotI", noSideEffect.} proc `not`*(x: int8): int8 {.magic: "BitnotI", noSideEffect.}
proc `not`*(x: int16): int16 {.magic: "BitnotI", noSideEffect.} proc `not`*(x: int16): int16 {.magic: "BitnotI", noSideEffect.}
proc `not`*(x: int32): int32 {.magic: "BitnotI", noSideEffect.} proc `not`*(x: int32): int32 {.magic: "BitnotI", noSideEffect.}
@ -207,34 +196,32 @@ proc `*`*(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int32): int32 {.magic: "MulI", noSideEffect.} proc `*`*(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
proc `*`*(x, y: int64): int64 {.magic: "MulI", noSideEffect.} proc `*`*(x, y: int64): int64 {.magic: "MulI", noSideEffect.}
proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.} =
## Computes the integer division. ## Computes the integer division.
## ##
## This is roughly the same as ``trunc(x/y)``. ## This is roughly the same as `math.trunc(x/y).int`.
## runnableExamples:
## .. code-block:: Nim assert (1 div 2) == 0
## ( 1 div 2) == 0 assert (2 div 2) == 1
## ( 2 div 2) == 1 assert (3 div 2) == 1
## ( 3 div 2) == 1 assert (7 div 3) == 2
## ( 7 div 3) == 2 assert (-7 div 3) == -2
## (-7 div 3) == -2 assert (7 div -3) == -2
## ( 7 div -3) == -2 assert (-7 div -3) == 2
## (-7 div -3) == 2
proc `div`*(x, y: int8): int8 {.magic: "DivI", noSideEffect.} proc `div`*(x, y: int8): int8 {.magic: "DivI", noSideEffect.}
proc `div`*(x, y: int16): int16 {.magic: "DivI", noSideEffect.} proc `div`*(x, y: int16): int16 {.magic: "DivI", noSideEffect.}
proc `div`*(x, y: int32): int32 {.magic: "DivI", noSideEffect.} proc `div`*(x, y: int32): int32 {.magic: "DivI", noSideEffect.}
proc `div`*(x, y: int64): int64 {.magic: "DivI", noSideEffect.} proc `div`*(x, y: int64): int64 {.magic: "DivI", noSideEffect.}
proc `mod`*(x, y: int): int {.magic: "ModI", noSideEffect.} proc `mod`*(x, y: int): int {.magic: "ModI", noSideEffect.} =
## Computes the integer modulo operation (remainder). ## Computes the integer modulo operation (remainder).
## ##
## This is the same as ``x - (x div y) * y``. ## This is the same as `x - (x div y) * y`.
## runnableExamples:
## .. code-block:: Nim assert (7 mod 5) == 2
## ( 7 mod 5) == 2 assert (-7 mod 5) == -2
## (-7 mod 5) == -2 assert (7 mod -5) == 2
## ( 7 mod -5) == 2 assert (-7 mod -5) == -2
## (-7 mod -5) == -2
proc `mod`*(x, y: int8): int8 {.magic: "ModI", noSideEffect.} proc `mod`*(x, y: int8): int8 {.magic: "ModI", noSideEffect.}
proc `mod`*(x, y: int16): int16 {.magic: "ModI", noSideEffect.} proc `mod`*(x, y: int16): int16 {.magic: "ModI", noSideEffect.}
proc `mod`*(x, y: int32): int32 {.magic: "ModI", noSideEffect.} proc `mod`*(x, y: int32): int32 {.magic: "ModI", noSideEffect.}
@ -248,7 +235,7 @@ when defined(nimOldShiftRight) or not defined(nimAshr):
proc `shr`*(x: int32, y: SomeInteger): int32 {.magic: "ShrI", noSideEffect, deprecated: shrDepMessage.} proc `shr`*(x: int32, y: SomeInteger): int32 {.magic: "ShrI", noSideEffect, deprecated: shrDepMessage.}
proc `shr`*(x: int64, y: SomeInteger): int64 {.magic: "ShrI", noSideEffect, deprecated: shrDepMessage.} proc `shr`*(x: int64, y: SomeInteger): int64 {.magic: "ShrI", noSideEffect, deprecated: shrDepMessage.}
else: else:
proc `shr`*(x: int, y: SomeInteger): int {.magic: "AshrI", noSideEffect.} proc `shr`*(x: int, y: SomeInteger): int {.magic: "AshrI", noSideEffect.} =
## Computes the `shift right` operation of `x` and `y`, filling ## Computes the `shift right` operation of `x` and `y`, filling
## vacant bit positions with the sign bit. ## vacant bit positions with the sign bit.
## ##
@ -256,38 +243,36 @@ else:
## is different than in *C*. ## is different than in *C*.
## ##
## See also: ## See also:
## * `ashr proc <#ashr,int,SomeInteger>`_ for arithmetic shift right ## * `ashr func<#ashr,int,SomeInteger>`_ for arithmetic shift right
## runnableExamples:
## .. code-block:: Nim assert 0b0001_0000'i8 shr 2 == 0b0000_0100'i8
## 0b0001_0000'i8 shr 2 == 0b0000_0100'i8 assert 0b0000_0001'i8 shr 1 == 0b0000_0000'i8
## 0b0000_0001'i8 shr 1 == 0b0000_0000'i8 assert 0b1000_0000'i8 shr 4 == 0b1111_1000'i8
## 0b1000_0000'i8 shr 4 == 0b1111_1000'i8 assert -1 shr 5 == -1
## -1 shr 5 == -1 assert 1 shr 5 == 0
## 1 shr 5 == 0 assert 16 shr 2 == 4
## 16 shr 2 == 4 assert -16 shr 2 == -4
## -16 shr 2 == -4
proc `shr`*(x: int8, y: SomeInteger): int8 {.magic: "AshrI", noSideEffect.} proc `shr`*(x: int8, y: SomeInteger): int8 {.magic: "AshrI", noSideEffect.}
proc `shr`*(x: int16, y: SomeInteger): int16 {.magic: "AshrI", noSideEffect.} proc `shr`*(x: int16, y: SomeInteger): int16 {.magic: "AshrI", noSideEffect.}
proc `shr`*(x: int32, y: SomeInteger): int32 {.magic: "AshrI", noSideEffect.} proc `shr`*(x: int32, y: SomeInteger): int32 {.magic: "AshrI", noSideEffect.}
proc `shr`*(x: int64, y: SomeInteger): int64 {.magic: "AshrI", noSideEffect.} proc `shr`*(x: int64, y: SomeInteger): int64 {.magic: "AshrI", noSideEffect.}
proc `shl`*(x: int, y: SomeInteger): int {.magic: "ShlI", noSideEffect.} proc `shl`*(x: int, y: SomeInteger): int {.magic: "ShlI", noSideEffect.} =
## Computes the `shift left` operation of `x` and `y`. ## Computes the `shift left` operation of `x` and `y`.
## ##
## **Note**: `Operator precedence <manual.html#syntax-precedence>`_ ## **Note**: `Operator precedence <manual.html#syntax-precedence>`_
## is different than in *C*. ## is different than in *C*.
## runnableExamples:
## .. code-block:: Nim assert 1'i32 shl 4 == 0x0000_0010
## 1'i32 shl 4 == 0x0000_0010 assert 1'i64 shl 4 == 0x0000_0000_0000_0010
## 1'i64 shl 4 == 0x0000_0000_0000_0010
proc `shl`*(x: int8, y: SomeInteger): int8 {.magic: "ShlI", noSideEffect.} proc `shl`*(x: int8, y: SomeInteger): int8 {.magic: "ShlI", noSideEffect.}
proc `shl`*(x: int16, y: SomeInteger): int16 {.magic: "ShlI", noSideEffect.} proc `shl`*(x: int16, y: SomeInteger): int16 {.magic: "ShlI", noSideEffect.}
proc `shl`*(x: int32, y: SomeInteger): int32 {.magic: "ShlI", noSideEffect.} proc `shl`*(x: int32, y: SomeInteger): int32 {.magic: "ShlI", noSideEffect.}
proc `shl`*(x: int64, y: SomeInteger): int64 {.magic: "ShlI", noSideEffect.} proc `shl`*(x: int64, y: SomeInteger): int64 {.magic: "ShlI", noSideEffect.}
when defined(nimAshr): when defined(nimAshr):
proc ashr*(x: int, y: SomeInteger): int {.magic: "AshrI", noSideEffect.} proc ashr*(x: int, y: SomeInteger): int {.magic: "AshrI", noSideEffect.} =
## Shifts right by pushing copies of the leftmost bit in from the left, ## Shifts right by pushing copies of the leftmost bit in from the left,
## and let the rightmost bits fall off. ## and let the rightmost bits fall off.
## ##
@ -295,12 +280,11 @@ when defined(nimAshr):
## call syntax for it. ## call syntax for it.
## ##
## See also: ## See also:
## * `shr proc <#shr,int,SomeInteger>`_ ## * `shr func<#shr,int,SomeInteger>`_
## runnableExamples:
## .. code-block:: Nim assert ashr(0b0001_0000'i8, 2) == 0b0000_0100'i8
## ashr(0b0001_0000'i8, 2) == 0b0000_0100'i8 assert ashr(0b1000_0000'i8, 8) == 0b1111_1111'i8
## ashr(0b1000_0000'i8, 8) == 0b1111_1111'i8 assert ashr(0b1000_0000'i8, 1) == 0b1100_0000'i8
## ashr(0b1000_0000'i8, 1) == 0b1100_0000'i8
proc ashr*(x: int8, y: SomeInteger): int8 {.magic: "AshrI", noSideEffect.} proc ashr*(x: int8, y: SomeInteger): int8 {.magic: "AshrI", noSideEffect.}
proc ashr*(x: int16, y: SomeInteger): int16 {.magic: "AshrI", noSideEffect.} proc ashr*(x: int16, y: SomeInteger): int16 {.magic: "AshrI", noSideEffect.}
proc ashr*(x: int32, y: SomeInteger): int32 {.magic: "AshrI", noSideEffect.} proc ashr*(x: int32, y: SomeInteger): int32 {.magic: "AshrI", noSideEffect.}
@ -309,34 +293,31 @@ else:
# used for bootstrapping the compiler # used for bootstrapping the compiler
proc ashr*[T](x: T, y: SomeInteger): T = discard proc ashr*[T](x: T, y: SomeInteger): T = discard
proc `and`*(x, y: int): int {.magic: "BitandI", noSideEffect.} proc `and`*(x, y: int): int {.magic: "BitandI", noSideEffect.} =
## Computes the `bitwise and` of numbers `x` and `y`. ## Computes the `bitwise and` of numbers `x` and `y`.
## runnableExamples:
## .. code-block:: Nim assert (0b0011 and 0b0101) == 0b0001
## (0b0011 and 0b0101) == 0b0001 assert (0b0111 and 0b1100) == 0b0100
## (0b0111 and 0b1100) == 0b0100
proc `and`*(x, y: int8): int8 {.magic: "BitandI", noSideEffect.} proc `and`*(x, y: int8): int8 {.magic: "BitandI", noSideEffect.}
proc `and`*(x, y: int16): int16 {.magic: "BitandI", noSideEffect.} proc `and`*(x, y: int16): int16 {.magic: "BitandI", noSideEffect.}
proc `and`*(x, y: int32): int32 {.magic: "BitandI", noSideEffect.} proc `and`*(x, y: int32): int32 {.magic: "BitandI", noSideEffect.}
proc `and`*(x, y: int64): int64 {.magic: "BitandI", noSideEffect.} proc `and`*(x, y: int64): int64 {.magic: "BitandI", noSideEffect.}
proc `or`*(x, y: int): int {.magic: "BitorI", noSideEffect.} proc `or`*(x, y: int): int {.magic: "BitorI", noSideEffect.} =
## Computes the `bitwise or` of numbers `x` and `y`. ## Computes the `bitwise or` of numbers `x` and `y`.
## runnableExamples:
## .. code-block:: Nim assert (0b0011 or 0b0101) == 0b0111
## (0b0011 or 0b0101) == 0b0111 assert (0b0111 or 0b1100) == 0b1111
## (0b0111 or 0b1100) == 0b1111
proc `or`*(x, y: int8): int8 {.magic: "BitorI", noSideEffect.} proc `or`*(x, y: int8): int8 {.magic: "BitorI", noSideEffect.}
proc `or`*(x, y: int16): int16 {.magic: "BitorI", noSideEffect.} proc `or`*(x, y: int16): int16 {.magic: "BitorI", noSideEffect.}
proc `or`*(x, y: int32): int32 {.magic: "BitorI", noSideEffect.} proc `or`*(x, y: int32): int32 {.magic: "BitorI", noSideEffect.}
proc `or`*(x, y: int64): int64 {.magic: "BitorI", noSideEffect.} proc `or`*(x, y: int64): int64 {.magic: "BitorI", noSideEffect.}
proc `xor`*(x, y: int): int {.magic: "BitxorI", noSideEffect.} proc `xor`*(x, y: int): int {.magic: "BitxorI", noSideEffect.} =
## Computes the `bitwise xor` of numbers `x` and `y`. ## Computes the `bitwise xor` of numbers `x` and `y`.
## runnableExamples:
## .. code-block:: Nim assert (0b0011 xor 0b0101) == 0b0110
## (0b0011 xor 0b0101) == 0b0110 assert (0b0111 xor 0b1100) == 0b1011
## (0b0111 xor 0b1100) == 0b1011
proc `xor`*(x, y: int8): int8 {.magic: "BitxorI", noSideEffect.} proc `xor`*(x, y: int8): int8 {.magic: "BitxorI", noSideEffect.}
proc `xor`*(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.} proc `xor`*(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.}
proc `xor`*(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.} proc `xor`*(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}