-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-pil.l
61 lines (60 loc) · 1.58 KB
/
test-pil.l
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
(gc 128)
(seed (in "/dev/urandom" (rd 8)))
(load "libgmp.l")
(de randL (N)
(pack
(make
(do N
(link (rand 1 9)) ) ) ) )
(de pil_cmp (X Y)
(cond
((< X Y) -1)
((> X Y) 1)
(T 0) ) )
# main
(let (A (mpz_malloc) B (mpz_malloc) Z (mpz_malloc))
(mpz_init A)
(mpz_init B)
(mpz_init Z)
(do 10000
(at (0 . 100) (prin ".") (flush))
(let
(X1 (randL (rand 50000 100000))
X2 (randL (rand 50000 100000))
Y1 (format X1)
Y2 (format X2) )
(mpz_set_str A X1)
(mpz_set_str B X2)
(mpz_add Z A B)
(test (+ Y1 Y2) (format (mpz_get_str Z)))
(mpz_sub Z A B)
(test (- Y1 Y2) (format (mpz_get_str Z)))
(mpz_mul Z A B)
(test (* Y1 Y2) (format (mpz_get_str Z)))
(mpz_tdiv_q Z A B)
(test (/ Y1 Y2) (format (mpz_get_str Z)))
(mpz_mod Z A B)
(test (% Y1 Y2) (format (mpz_get_str Z)))
(let (P (pil_cmp Y1 Y2) G (mpz_cmp A B))
(cond
((and (gt0 P) (gt0 G)))
((and (lt0 P) (lt0 G)))
((and (=0 P) (=0 G)))
(T (quit "Comparison failed")) ) )
(mpz_sqrt Z A)
(test (sqrt Y1) (format (mpz_get_str Z)))
(mpz_and Z A B)
(test (& Y1 Y2) (format (mpz_get_str Z)))
(mpz_ior Z A B)
(test (| Y1 Y2) (format (mpz_get_str Z)))
(mpz_xor Z A B)
(test (x| Y1 Y2) (format (mpz_get_str Z)))
) # let
) # do
(mpz_free A)
(mpz_free B)
(mpz_free Z)
)
(prinl)
(msg 'All-ok)
(bye)