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-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
import ./binary_ops/addsub_impl,
|
|
|
|
./binary_ops/mul_impl
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
export addsub_impl, mul_impl
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
when isMainModule:
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
import typetraits
|
|
|
|
import ./uint_init
|
2018-02-15 22:28:31 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
let a = toMpUint(10'u32)
|
2018-02-15 22:28:31 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
echo "a: " & $a
|
|
|
|
echo "a+a: " & $(a+a)
|
2018-02-15 19:26:10 +00:00
|
|
|
|
2018-03-20 15:04:19 +00:00
|
|
|
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-02-16 08:22:23 +00:00
|
|
|
|
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))
|