File: fixnum-tests.scm

package info (click to toggle)
chicken 5.3.0-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,892 kB
  • sloc: ansic: 580,083; lisp: 71,987; tcl: 1,445; sh: 588; makefile: 60
file content (36 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (3)
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)))