nim-stint/src/private/uint_comparison.nim

41 lines
1.2 KiB
Nim
Raw Normal View History

2018-03-02 10:48:08 +00:00
# Mpint
# 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-04-21 11:50:43 +00:00
import ./uint_type, ./as_words
2018-02-17 16:57:26 +00:00
func isZero*(n: SomeUnsignedInt): bool {.inline.} =
n == 0
2018-02-17 16:57:26 +00:00
2018-04-25 10:52:00 +00:00
func isZero*(n: UintImpl): bool {.inline.} =
asWords(n, ignoreEndianness = true):
if n != 0:
2018-04-21 11:50:43 +00:00
return false
return true
2018-04-25 10:52:00 +00:00
func `<`*(x, y: UintImpl): bool {.inline.}=
2018-04-21 11:50:43 +00:00
# Lower comparison for multi-precision integers
asWordsZip(x, y, ignoreEndianness = false):
if x != y:
return x < y
2018-04-21 11:50:43 +00:00
return false # they're equal
2018-04-25 10:52:00 +00:00
func `==`*(x, y: UintImpl): bool {.inline.}=
# Equal comparison for multi-precision integers
asWordsZip(x, y, ignoreEndianness = true):
if x != y:
2018-04-21 11:50:43 +00:00
return false
return true # they're equal
2018-04-25 10:52:00 +00:00
func `<=`*(x, y: UintImpl): bool {.inline.}=
# Lower or equal comparison for multi-precision integers
asWordsZip(x, y, ignoreEndianness = false):
if x != y:
return x < y
return true # they're equal