nim-stint/src/uint_binary_ops.nim

33 lines
929 B
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.
import ./binary_ops/addsub_impl,
./binary_ops/mul_impl
export addsub_impl, mul_impl
when isMainModule:
import typetraits
import ./uint_init
2018-02-15 22:28:31 +00:00
let a = toMpUint(10'u32)
2018-02-15 22:28:31 +00:00
echo "a: " & $a
echo "a+a: " & $(a+a)
let z = a * a
2018-03-20 15:12:42 +00:00
echo "a * a: " & $z # How did the result value change?
echo "a * a type: " & $z.type.name
2018-03-20 15:14:31 +00:00
# Compile without release: memory corruption
# In release: no corruption
# Comment out the "naiveMul" in mul_impl: no corruption
2018-03-20 15:12:42 +00:00
echo "Is memory corrupted: " & $(z != toMpUint(100'u32))