-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixnum-tests.scm
36 lines (32 loc) · 988 Bytes
/
fixnum-tests.scm
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
(import (chicken platform)
(chicken fixnum))
(define (fxo+ x y) (##core#inline "C_i_o_fixnum_plus" x y))
(define (fxo- x y) (##core#inline "C_i_o_fixnum_difference" x y))
(define-syntax assert
;; compiling with -unsafe disables the original assert
(ir-macro-transformer
(lambda (e inj cmp)
(apply
(lambda (f)
`(if (not ,f)
(error "assert" ',f)))
(cdr e)))))
(assert (= 4 (fxo+ 2 2)))
(assert (= -26 (fxo+ 74 -100)))
(assert (= 1073741823 (fxo+ #x3ffffffe 1)))
(assert
(if (feature? #:64bit)
(not (fxo+ #x3fffffffffffffff 1))
(not (fxo+ #x3fffffff 1))))
(assert (= 4 (fxo- 6 2)))
(assert (= -4 (fxo- 1000 1004)))
(assert (= 2004 (fxo- 1000 -1004)))
(assert
(if (feature? #:64bit)
(= -4611686018427387904 (fxo- (- #x3fffffffffffffff) 1))
(= -1073741824 (fxo- (- #x3fffffff) 1))))
(assert
(if (feature? #:64bit)
(not (fxo- (- #x3fffffffffffffff) 2))
(not (fxo- (- #x3fffffff) 2))))
(assert (= (modulo -3 4) (fxmod -3 4)))