~ chicken-core (chicken-5) /tests/fixnum-tests.scm
Trap1(import (chicken platform)
2 (chicken fixnum))
3
4(define (fxo+ x y) (##core#inline "C_i_o_fixnum_plus" x y))
5(define (fxo- x y) (##core#inline "C_i_o_fixnum_difference" x y))
6
7(define-syntax assert
8 ;; compiling with -unsafe disables the original assert
9 (ir-macro-transformer
10 (lambda (e inj cmp)
11 (apply
12 (lambda (f)
13 `(if (not ,f)
14 (error "assert" ',f)))
15 (cdr e)))))
16
17(assert (= 4 (fxo+ 2 2)))
18(assert (= -26 (fxo+ 74 -100)))
19(assert (= 1073741823 (fxo+ #x3ffffffe 1)))
20(assert
21 (if (feature? #:64bit)
22 (not (fxo+ #x3fffffffffffffff 1))
23 (not (fxo+ #x3fffffff 1))))
24(assert (= 4 (fxo- 6 2)))
25(assert (= -4 (fxo- 1000 1004)))
26(assert (= 2004 (fxo- 1000 -1004)))
27(assert
28 (if (feature? #:64bit)
29 (= -4611686018427387904 (fxo- (- #x3fffffffffffffff) 1))
30 (= -1073741824 (fxo- (- #x3fffffff) 1))))
31(assert
32 (if (feature? #:64bit)
33 (not (fxo- (- #x3fffffffffffffff) 2))
34 (not (fxo- (- #x3fffffff) 2))))
35
36(assert (= (modulo -3 4) (fxmod -3 4)))