Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
97 lines (85 sloc) 1.23 KB
#
evaluate
(
use "bn.fxl";
#use "test.fxl";
#use_lib "time.fxl";
standard
) \;
#do_benchmark;
#trace_elapsed;
\test_bn==
(
\test_ops==
(
\run_test=
(
\show=(\k\v put [k" = "] say (bn_str v))
\label\fn
say ["= test "label]
\try=
(\x\y
\x=(str_bn x)
\y=(str_bn y)
\z=(fn x y)
show "x" x
show "y" y
show "z" z
nl
)
\try2=(\x try x x)
try "0" "0"
try "1" "1"
try "10002" "10003"
try "12370356088" "15123"
try "123470356088" "15123"
try "26019123470356088" "1049752133674165355933"
try2 "999999999999999999999999"
try2 "1111111111111111111111111111111111111111111111111"
)
run_test "bn_add" bn_add
run_test "bn_mul" bn_mul
(
# Compute 2^256.
\x=(str_bn "2") # 2^1
\x=(bn_mul x x) # 2^2
\x=(bn_mul x x) # 2^4
\x=(bn_mul x x) # 2^8
\x=(bn_mul x x) # 2^16
\x=(bn_mul x x) # 2^32
\x=(bn_mul x x) # 2^64
\x=(bn_mul x x) # 2^128
\x=(bn_mul x x) # 2^256
\s=(bn_str x)
say s
say (length s)
)
)
\test_convert==
(
\try=
(\x
\xn=(str_bn x)
\y=(bn_str xn)
say [(as_str x)" "(as_str y)]
)
say "= test str_bn"
try "0"
try "1"
try "1234"
try "9999"
try "00"
try "1234567890123456789012"
try "1234567890"
try "000000123"
# Test some errors.
try ""
try "x"
try "x1234"
try "12345abc90123456789012"
nl
)
test_ops
test_convert
)
test_bn
You can’t perform that action at this time.