-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathb20.fxl
90 lines (79 loc) · 1.24 KB
/
b20.fxl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
#trace_elapsed;
show_benchmark;
\\test_bn=
(
\\test_ops=
(
\run_test=
(
\show=(\k\v say [k" = "v])
\label\fn
say ["= test "label]
\try=
(\x\y
\x=(bn_from_dec x)
\y=(bn_from_dec 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 "add" bn_add
run_test "mul" bn_mul
(
# Compute 2^256.
\x=(bn_from_dec "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_to_dec x)
say s
say (length s)
)
)
\\test_convert=
(
\try=
(\x
\xn=(bn_from_dec x)
\y=(bn_to_dec xn)
say [(as_str x)" "(as_str y)]
)
say "= test convert"
try "0"
try "1"
try "1234"
try "9999"
try "00"
try "1234567890123456789012"
try "1234567890"
try "000000123"
# Test some errors.
# LATER 20211110 These don't map to void anymore, but perhaps they should.
try ""
try "x"
try "x1234"
try "12345abc90123456789012"
nl
)
test_ops
test_convert
)
test_bn