2018-04-25 21:21:25 +02:00
|
|
|
# Stint
|
2018-03-02 11:48:08 +01:00
|
|
|
# Copyright 2018 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
#
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
|
|
|
#
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
2018-02-16 17:48:54 +01:00
|
|
|
|
2018-10-25 12:58:40 +02:00
|
|
|
import ./datatypes
|
2018-02-17 17:57:26 +01:00
|
|
|
|
2018-04-21 12:12:05 +02:00
|
|
|
func isZero*(n: SomeUnsignedInt): bool {.inline.} =
|
2018-03-26 12:45:10 +02:00
|
|
|
n == 0
|
2018-02-17 17:57:26 +01:00
|
|
|
|
2018-04-25 12:52:00 +02:00
|
|
|
func isZero*(n: UintImpl): bool {.inline.} =
|
2018-10-25 12:58:40 +02:00
|
|
|
n.hi.isZero and n.lo.isZero
|
2018-04-21 13:50:43 +02:00
|
|
|
|
2018-04-25 12:52:00 +02:00
|
|
|
func `<`*(x, y: UintImpl): bool {.inline.}=
|
2018-04-21 13:50:43 +02:00
|
|
|
# Lower comparison for multi-precision integers
|
2018-10-25 12:58:40 +02:00
|
|
|
x.hi < y.hi or
|
|
|
|
(x.hi == y.hi and x.lo < y.lo)
|
2018-04-21 13:50:43 +02:00
|
|
|
|
2018-04-25 12:52:00 +02:00
|
|
|
func `==`*(x, y: UintImpl): bool {.inline.}=
|
2018-03-26 16:05:19 +02:00
|
|
|
# Equal comparison for multi-precision integers
|
2018-10-25 12:58:40 +02:00
|
|
|
x.hi == y.hi and x.lo == y.lo
|
2018-03-26 16:05:19 +02:00
|
|
|
|
2018-04-25 12:52:00 +02:00
|
|
|
func `<=`*(x, y: UintImpl): bool {.inline.}=
|
2018-03-26 16:05:19 +02:00
|
|
|
# Lower or equal comparison for multi-precision integers
|
2018-10-25 12:58:40 +02:00
|
|
|
x.hi < y.hi or
|
|
|
|
(x.hi == y.hi and x.lo <= y.lo)
|
2018-05-16 10:41:46 +02:00
|
|
|
|
2018-10-25 12:58:40 +02:00
|
|
|
func isEven*(x: SomeUnsignedInt): bool {.inline.} =
|
|
|
|
(x and 1) == 0
|
2018-05-16 10:41:46 +02:00
|
|
|
|
|
|
|
func isEven*(x: UintImpl): bool {.inline.}=
|
2018-10-25 12:58:40 +02:00
|
|
|
x.lo.isEven
|
|
|
|
|
|
|
|
func isOdd*(x: SomeUnsignedInt): bool {.inline.} =
|
|
|
|
not x.isEven
|
|
|
|
|
|
|
|
func isOdd*(x: UintImpl): bool {.inline.}=
|
|
|
|
not x.isEven
|