PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/Examples/test-suite/schemerunme/integers.scm

#
Lisp | 28 lines | 19 code | 3 blank | 6 comment | 0 complexity | 4b6c728f8e3667a3100b68986964def3 MD5 | raw file
 1(define-macro (check-equality form1 form2)
 2  `(let ((result1 ,form1)
 3	 (result2 ,form2))
 4     (if (not (equal? result1 result2))
 5	 (error "Check failed:"
 6		(list 'equal? ',form1 ',form2)
 7		result1 result2))))
 8
 9(define-macro (check-range function from to)
10  `(begin (check-equality (,function ,from) ,from)
11	  (check-equality (,function ,to)   ,to)
12	  (check-equality (throws-exception? (,function (- ,from 1))) #t)
13	  (check-equality (throws-exception? (,function (+ ,to 1))) #t)))
14
15;;; signed char, unsigned char typemaps deal with characters, not integers.
16;; (check-range signed-char-identity (- (expt 2 7)) (- (expt 2 7) 1))
17;; (check-range unsigned-char-identity 0 (- (expt 2 8) 1))
18(check-range signed-short-identity (- (expt 2 15)) (- (expt 2 15) 1))
19(check-range unsigned-short-identity 0 (- (expt 2 16) 1))
20(check-range signed-int-identity (- (expt 2 31)) (- (expt 2 31) 1))
21(check-range unsigned-int-identity 0 (- (expt 2 32) 1))
22(check-range signed-long-identity (- (expt 2 31)) (- (expt 2 31) 1))
23(check-range unsigned-long-identity 0 (- (expt 2 32) 1))
24;;; long long not implemented in Guile and MzScheme.
25;; (check-range signed-long-long-identity (- (expt 2 63)) (- (expt 2 63) 1))
26;; (check-range unsigned-long-long-identity 0 (- (expt 2 64) 1))
27
28(exit 0)