mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-13 17:20:21 +02:00
1320 lines
27 KiB
Scheme
1320 lines
27 KiB
Scheme
;;;; numbers.test --- tests guile's numbers -*- scheme -*-
|
|
;;;; Copyright (C) 2000, 2001 Free Software Foundation, Inc.
|
|
;;;;
|
|
;;;; This program is free software; you can redistribute it and/or modify
|
|
;;;; it under the terms of the GNU General Public License as published by
|
|
;;;; the Free Software Foundation; either version 2, or (at your option)
|
|
;;;; any later version.
|
|
;;;;
|
|
;;;; This program is distributed in the hope that it will be useful,
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
;;;; GNU General Public License for more details.
|
|
;;;;
|
|
;;;; You should have received a copy of the GNU General Public License
|
|
;;;; along with this software; see the file COPYING. If not, write to
|
|
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
|
|
;;;; Boston, MA 02111-1307 USA
|
|
;;;;
|
|
;;;; As a special exception, the Free Software Foundation gives permission
|
|
;;;; for additional uses of the text contained in its release of GUILE.
|
|
;;;;
|
|
;;;; The exception is that, if you link the GUILE library with other files
|
|
;;;; to produce an executable, this does not by itself cause the
|
|
;;;; resulting executable to be covered by the GNU General Public License.
|
|
;;;; Your use of that executable is in no way restricted on account of
|
|
;;;; linking the GUILE library code into it.
|
|
;;;;
|
|
;;;; This exception does not however invalidate any other reasons why
|
|
;;;; the executable file might be covered by the GNU General Public License.
|
|
;;;;
|
|
;;;; This exception applies only to the code released by the
|
|
;;;; Free Software Foundation under the name GUILE. If you copy
|
|
;;;; code from other Free Software Foundation releases into a copy of
|
|
;;;; GUILE, as the General Public License permits, the exception does
|
|
;;;; not apply to the code that you add in this way. To avoid misleading
|
|
;;;; anyone as to the status of such modified files, you must delete
|
|
;;;; this exception notice from them.
|
|
;;;;
|
|
;;;; If you write modifications of your own for GUILE, it is your choice
|
|
;;;; whether to permit this exception to apply to your modifications.
|
|
;;;; If you do not wish that, delete this exception notice.
|
|
|
|
(use-modules (ice-9 documentation))
|
|
|
|
|
|
;;;
|
|
;;; miscellaneous
|
|
;;;
|
|
|
|
(define (documented? object)
|
|
(not (not (object-documentation object))))
|
|
|
|
(define fixnum-bit
|
|
(inexact->exact (+ (/ (log (+ most-positive-fixnum 1)) (log 2)) 1)))
|
|
|
|
(define fixnum-min most-negative-fixnum)
|
|
(define fixnum-max most-positive-fixnum)
|
|
|
|
|
|
;;;
|
|
;;; exact?
|
|
;;;
|
|
|
|
(with-test-prefix "exact?"
|
|
|
|
(pass-if "documented?"
|
|
(documented? exact?))
|
|
|
|
(with-test-prefix "integers"
|
|
|
|
(pass-if "0"
|
|
(exact? 0))
|
|
|
|
(pass-if "fixnum-max"
|
|
(exact? fixnum-max))
|
|
|
|
(pass-if "fixnum-max + 1"
|
|
(exact? (+ fixnum-max 1)))
|
|
|
|
(pass-if "fixnum-min"
|
|
(exact? fixnum-min))
|
|
|
|
(pass-if "fixnum-min - 1"
|
|
(exact? (- fixnum-min 1))))
|
|
|
|
(with-test-prefix "reals"
|
|
|
|
;; (FIXME: need better examples.)
|
|
|
|
(pass-if "sqrt (fixnum-max^2 - 1)"
|
|
(eq? #f (exact? (sqrt (- (expt fixnum-max 2) 1)))))
|
|
|
|
(pass-if "sqrt ((fixnum-max+1)^2 - 1)"
|
|
(eq? #f (exact? (sqrt (- (expt (+ fixnum-max 1) 2) 1)))))))
|
|
|
|
;;;
|
|
;;; odd?
|
|
;;;
|
|
|
|
|
|
;;;
|
|
;;; even?
|
|
;;;
|
|
|
|
|
|
;;;
|
|
;;; abs
|
|
;;;
|
|
|
|
|
|
;;;
|
|
;;; quotient
|
|
;;;
|
|
|
|
(with-test-prefix "quotient"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? quotient))
|
|
|
|
(with-test-prefix "0 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (quotient 0 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (quotient 0 -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? 0 (quotient 0 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (quotient 0 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (quotient 0 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (quotient 0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient 0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "1 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (quotient 1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? -1 (quotient 1 -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? 0 (quotient 1 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (quotient 1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (quotient 1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (quotient 1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient 1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "-1 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? -1 (quotient -1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (quotient -1 -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? 0 (quotient -1 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (quotient -1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (quotient -1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (quotient -1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient -1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-max / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? fixnum-max (quotient fixnum-max 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? (- fixnum-max) (quotient fixnum-max -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? fixnum-max (+ (* (quotient fixnum-max 2) 2) 1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (quotient fixnum-max fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (quotient fixnum-max (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (quotient fixnum-max fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient fixnum-max (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-max + 1) / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? (+ fixnum-max 1) (quotient (+ fixnum-max 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? (- (+ fixnum-max 1)) (quotient (+ fixnum-max 1) -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? (+ fixnum-max 1) (* (quotient (+ fixnum-max 1) 2) 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (quotient (+ fixnum-max 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (quotient (+ fixnum-max 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (quotient (+ fixnum-max 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient (+ fixnum-max 1) (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-min / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? fixnum-min (quotient fixnum-min 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? (- fixnum-min) (quotient fixnum-min -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? fixnum-min (* (quotient fixnum-min 2) 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? -1 (quotient fixnum-min fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? -1 (quotient fixnum-min (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (quotient fixnum-min fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (quotient fixnum-min (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-min - 1) / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? (- fixnum-min 1) (quotient (- fixnum-min 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? (- (- fixnum-min 1)) (quotient (- fixnum-min 1) -1)))
|
|
|
|
(pass-if "n = 2"
|
|
(eqv? fixnum-min (* (quotient (- fixnum-min 1) 2) 2)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? -1 (quotient (- fixnum-min 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? -1 (quotient (- fixnum-min 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (quotient (- fixnum-min 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (quotient (- fixnum-min 1) (- fixnum-min 1)))))
|
|
|
|
;; Positive dividend and divisor
|
|
|
|
(pass-if "35 / 7"
|
|
(eqv? 5 (quotient 35 7)))
|
|
|
|
;; Negative dividend, positive divisor
|
|
|
|
(pass-if "-35 / 7"
|
|
(eqv? -5 (quotient -35 7)))
|
|
|
|
;; Positive dividend, negative divisor
|
|
|
|
(pass-if "35 / -7"
|
|
(eqv? -5 (quotient 35 -7)))
|
|
|
|
;; Negative dividend and divisor
|
|
|
|
(pass-if "-35 / -7"
|
|
(eqv? 5 (quotient -35 -7)))
|
|
|
|
;; Are numerical overflows detected correctly?
|
|
|
|
;; Are wrong type arguments detected correctly?
|
|
|
|
)
|
|
|
|
;;;
|
|
;;; remainder
|
|
;;;
|
|
|
|
(with-test-prefix "remainder"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? remainder))
|
|
|
|
(with-test-prefix "0 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder 0 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder 0 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (remainder 0 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (remainder 0 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (remainder 0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (remainder 0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "1 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder 1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder 1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (remainder 1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (remainder 1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (remainder 1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (remainder 1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "-1 / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder -1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder -1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? -1 (remainder -1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? -1 (remainder -1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (remainder -1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? -1 (remainder -1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-max / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder fixnum-max 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder fixnum-max -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (remainder fixnum-max fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? fixnum-max (remainder fixnum-max (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? fixnum-max (remainder fixnum-max fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? fixnum-max (remainder fixnum-max (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-max + 1) / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder (+ fixnum-max 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder (+ fixnum-max 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (remainder (+ fixnum-max 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (remainder (+ fixnum-max 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (remainder (+ fixnum-max 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? (+ fixnum-max 1) (remainder (+ fixnum-max 1) (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-min / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder fixnum-min 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder fixnum-min -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? -1 (remainder fixnum-min fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (remainder fixnum-min (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (remainder fixnum-min fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? fixnum-min (remainder fixnum-min (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-min - 1) / n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (remainder (- fixnum-min 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (remainder (- fixnum-min 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? -2 (remainder (- fixnum-min 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? -1 (remainder (- fixnum-min 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (remainder (- fixnum-min 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (remainder (- fixnum-min 1) (- fixnum-min 1)))))
|
|
|
|
;; Positive dividend and divisor
|
|
|
|
(pass-if "35 / 7"
|
|
(eqv? 0 (remainder 35 7)))
|
|
|
|
;; Negative dividend, positive divisor
|
|
|
|
(pass-if "-35 / 7"
|
|
(eqv? 0 (remainder -35 7)))
|
|
|
|
;; Positive dividend, negative divisor
|
|
|
|
(pass-if "35 / -7"
|
|
(eqv? 0 (remainder 35 -7)))
|
|
|
|
;; Negative dividend and divisor
|
|
|
|
(pass-if "-35 / -7"
|
|
(eqv? 0 (remainder -35 -7)))
|
|
|
|
;; Are numerical overflows detected correctly?
|
|
|
|
;; Are wrong type arguments detected correctly?
|
|
|
|
)
|
|
|
|
;;;
|
|
;;; modulo
|
|
;;;
|
|
|
|
(with-test-prefix "modulo"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? modulo))
|
|
|
|
(with-test-prefix "0 % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo 0 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo 0 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (modulo 0 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (modulo 0 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (modulo 0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (modulo 0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "1 % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo 1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo 1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (modulo 1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (modulo 1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? (+ fixnum-min 1) (modulo 1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? fixnum-min (modulo 1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "-1 % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo -1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo -1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? (- fixnum-max 1) (modulo -1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? fixnum-max (modulo -1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (modulo -1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? -1 (modulo -1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-max % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo fixnum-max 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo fixnum-max -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 0 (modulo fixnum-max fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? fixnum-max (modulo fixnum-max (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (modulo fixnum-max fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? -2 (modulo fixnum-max (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-max + 1) % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo (+ fixnum-max 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo (+ fixnum-max 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (modulo (+ fixnum-max 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (modulo (+ fixnum-max 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (modulo (+ fixnum-max 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? -1 (modulo (+ fixnum-max 1) (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "fixnum-min % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo fixnum-min 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo fixnum-min -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? (- fixnum-max 1) (modulo fixnum-min fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 0 (modulo fixnum-min (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 0 (modulo fixnum-min fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? fixnum-min (modulo fixnum-min (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-min - 1) % n"
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 0 (modulo (- fixnum-min 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 0 (modulo (- fixnum-min 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? (- fixnum-max 2) (modulo (- fixnum-min 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? fixnum-max (modulo (- fixnum-min 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? -1 (modulo (- fixnum-min 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 0 (modulo (- fixnum-min 1) (- fixnum-min 1)))))
|
|
|
|
;; Positive dividend and divisor
|
|
|
|
(pass-if "13 % 4"
|
|
(eqv? 1 (modulo 13 4)))
|
|
|
|
(pass-if "2177452800 % 86400"
|
|
(eqv? 0 (modulo 2177452800 86400)))
|
|
|
|
;; Negative dividend, positive divisor
|
|
|
|
(pass-if "-13 % 4"
|
|
(eqv? 3 (modulo -13 4)))
|
|
|
|
(pass-if "-2177452800 % 86400"
|
|
(eqv? 0 (modulo -2177452800 86400)))
|
|
|
|
;; Positive dividend, negative divisor
|
|
|
|
(pass-if "13 % -4"
|
|
(eqv? -3 (modulo 13 -4)))
|
|
|
|
(pass-if "2177452800 % -86400"
|
|
(eqv? 0 (modulo 2177452800 -86400)))
|
|
|
|
;; Negative dividend and divisor
|
|
|
|
(pass-if "-13 % -4"
|
|
(eqv? -1 (modulo -13 -4)))
|
|
|
|
(pass-if "-2177452800 % -86400"
|
|
(eqv? 0 (modulo -2177452800 -86400)))
|
|
|
|
;; Are numerical overflows detected correctly?
|
|
|
|
;; Are wrong type arguments detected correctly?
|
|
|
|
)
|
|
|
|
;;;
|
|
;;; gcd
|
|
;;;
|
|
|
|
(with-test-prefix "gcd"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? gcd))
|
|
|
|
(with-test-prefix "(0 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? 0 (gcd 0 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd 0 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd 0 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? fixnum-max (gcd 0 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? (+ fixnum-max 1) (gcd 0 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? (- fixnum-min) (gcd 0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? (- (- fixnum-min 1)) (gcd 0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(1 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? 1 (gcd 1 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd 1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd 1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (gcd 1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (gcd 1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (gcd 1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (gcd 1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(-1 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? 1 (gcd -1 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd -1 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd -1 -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (gcd -1 fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (gcd -1 (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (gcd -1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (gcd -1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-max n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? fixnum-max (gcd fixnum-max 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd fixnum-max 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd fixnum-max -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? fixnum-max (gcd fixnum-max fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (gcd fixnum-max (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (gcd fixnum-max fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (gcd fixnum-max (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "((+ fixnum-max 1) n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd (+ fixnum-max 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd (+ fixnum-max 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (gcd (+ fixnum-max 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (gcd (+ fixnum-max 1) (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(fixnum-min n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? (- fixnum-min) (gcd fixnum-min 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd fixnum-min 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd fixnum-min -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (gcd fixnum-min fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? (+ fixnum-max 1) (gcd fixnum-min (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? (- fixnum-min) (gcd fixnum-min fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? 1 (gcd fixnum-min (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "((- fixnum-min 1) n)"
|
|
|
|
(pass-if "n = 0"
|
|
(eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) 0)))
|
|
|
|
(pass-if "n = 1"
|
|
(eqv? 1 (gcd (- fixnum-min 1) 1)))
|
|
|
|
(pass-if "n = -1"
|
|
(eqv? 1 (gcd (- fixnum-min 1) -1)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(eqv? 1 (gcd (- fixnum-min 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(eqv? 1 (gcd (- fixnum-min 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(eqv? 1 (gcd (- fixnum-min 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) (- fixnum-min 1)))))
|
|
|
|
;; Are wrong type arguments detected correctly?
|
|
|
|
)
|
|
|
|
;;;
|
|
;;; lcm
|
|
;;;
|
|
|
|
;;;
|
|
;;; number->string
|
|
;;;
|
|
|
|
;;;
|
|
;;; string->number
|
|
;;;
|
|
|
|
;;;
|
|
;;; number?
|
|
;;;
|
|
|
|
;;;
|
|
;;; complex?
|
|
;;;
|
|
|
|
;;;
|
|
;;; real?
|
|
;;;
|
|
|
|
;;;
|
|
;;; rational?
|
|
;;;
|
|
|
|
;;;
|
|
;;; integer?
|
|
;;;
|
|
|
|
;;;
|
|
;;; inexact?
|
|
;;;
|
|
|
|
;;;
|
|
;;; =
|
|
;;;
|
|
|
|
;;;
|
|
;;; <
|
|
;;;
|
|
|
|
(with-test-prefix "<"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? <))
|
|
|
|
(with-test-prefix "(< 0 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< 0 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< 0 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(< 0 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< 0 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< 0 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< 0 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< 0 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< 0 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< 0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< 0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< 0.0 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< 0.0 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< 0.0 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(< 0.0 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< 0.0 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< 0.0 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< 0.0 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< 0.0 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< 0.0 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< 0.0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< 0.0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< 1 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< 1 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< 1 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(not (< 1 1)))
|
|
|
|
(pass-if "n = 1.0"
|
|
(not (< 1 1.0)))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< 1 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< 1 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< 1 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< 1 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< 1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< 1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< 1.0 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< 1.0 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< 1.0 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(not (< 1.0 1)))
|
|
|
|
(pass-if "n = 1.0"
|
|
(not (< 1.0 1.0)))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< 1.0 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< 1.0 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< 1.0 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< 1.0 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< 1.0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< 1.0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< -1 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(< -1 0))
|
|
|
|
(pass-if "n = 0.0"
|
|
(< -1 0.0))
|
|
|
|
(pass-if "n = 1"
|
|
(< -1 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< -1 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< -1 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< -1 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< -1 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< -1 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< -1 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< -1 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< -1.0 n)"
|
|
|
|
(pass-if "n = 0"
|
|
(< -1.0 0))
|
|
|
|
(pass-if "n = 0.0"
|
|
(< -1.0 0.0))
|
|
|
|
(pass-if "n = 1"
|
|
(< -1.0 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< -1.0 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< -1.0 -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< -1.0 -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< -1.0 fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< -1.0 (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< -1.0 fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< -1.0 (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< fixnum-max n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< fixnum-max 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< fixnum-max 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(not (< fixnum-max 1)))
|
|
|
|
(pass-if "n = 1.0"
|
|
(not (< fixnum-max 1.0)))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< fixnum-max -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< fixnum-max -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(not (< fixnum-max fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< fixnum-max (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< fixnum-max fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< fixnum-max (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< (+ fixnum-max 1) n)"
|
|
|
|
(pass-if "n = 0"
|
|
(not (< (+ fixnum-max 1) 0)))
|
|
|
|
(pass-if "n = 0.0"
|
|
(not (< (+ fixnum-max 1) 0.0)))
|
|
|
|
(pass-if "n = 1"
|
|
(not (< (+ fixnum-max 1) 1)))
|
|
|
|
(pass-if "n = 1.0"
|
|
(not (< (+ fixnum-max 1) 1.0)))
|
|
|
|
(pass-if "n = -1"
|
|
(not (< (+ fixnum-max 1) -1)))
|
|
|
|
(pass-if "n = -1.0"
|
|
(not (< (+ fixnum-max 1) -1.0)))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(not (< (+ fixnum-max 1) fixnum-max)))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(not (< (+ fixnum-max 1) (+ fixnum-max 1))))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< (+ fixnum-max 1) fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< (+ fixnum-max 1) (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< fixnum-min n)"
|
|
|
|
(pass-if "n = 0"
|
|
(< fixnum-min 0))
|
|
|
|
(pass-if "n = 0.0"
|
|
(< fixnum-min 0.0))
|
|
|
|
(pass-if "n = 1"
|
|
(< fixnum-min 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< fixnum-min 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(< fixnum-min -1))
|
|
|
|
(pass-if "n = -1.0"
|
|
(< fixnum-min -1.0))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< fixnum-min fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< fixnum-min (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(not (< fixnum-min fixnum-min)))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< fixnum-min (- fixnum-min 1)))))
|
|
|
|
(with-test-prefix "(< (- fixnum-min 1) n)"
|
|
|
|
(pass-if "n = 0"
|
|
(< (- fixnum-min 1) 0))
|
|
|
|
(pass-if "n = 0.0"
|
|
(< (- fixnum-min 1) 0.0))
|
|
|
|
(pass-if "n = 1"
|
|
(< (- fixnum-min 1) 1))
|
|
|
|
(pass-if "n = 1.0"
|
|
(< (- fixnum-min 1) 1.0))
|
|
|
|
(pass-if "n = -1"
|
|
(< (- fixnum-min 1) -1))
|
|
|
|
(pass-if "n = -1.0"
|
|
(< (- fixnum-min 1) -1.0))
|
|
|
|
(pass-if "n = fixnum-max"
|
|
(< (- fixnum-min 1) fixnum-max))
|
|
|
|
(pass-if "n = fixnum-max + 1"
|
|
(< (- fixnum-min 1) (+ fixnum-max 1)))
|
|
|
|
(pass-if "n = fixnum-min"
|
|
(< (- fixnum-min 1) fixnum-min))
|
|
|
|
(pass-if "n = fixnum-min - 1"
|
|
(not (< (- fixnum-min 1) (- fixnum-min 1))))))
|
|
|
|
;;;
|
|
;;; >
|
|
;;;
|
|
|
|
;;;
|
|
;;; <=
|
|
;;;
|
|
|
|
;;;
|
|
;;; >=
|
|
;;;
|
|
|
|
;;;
|
|
;;; zero?
|
|
;;;
|
|
|
|
;;;
|
|
;;; positive?
|
|
;;;
|
|
|
|
;;;
|
|
;;; negative?
|
|
;;;
|
|
|
|
;;;
|
|
;;; max
|
|
;;;
|
|
|
|
;;;
|
|
;;; min
|
|
;;;
|
|
|
|
;;;
|
|
;;; +
|
|
;;;
|
|
|
|
(with-test-prefix "+"
|
|
|
|
(expect-fail "documented?"
|
|
(documented? +))
|
|
|
|
(with-test-prefix "wrong type argument"
|
|
|
|
(pass-if-exception "1st argument string"
|
|
exception:wrong-type-arg
|
|
(+ "1" 2))
|
|
|
|
(pass-if-exception "2nd argument bool"
|
|
exception:wrong-type-arg
|
|
(+ 1 #f))))
|
|
;;;
|
|
;;; -
|
|
;;;
|
|
|
|
;;;
|
|
;;; *
|
|
;;;
|
|
|
|
;;;
|
|
;;; /
|
|
;;;
|
|
|
|
;;;
|
|
;;; truncate
|
|
;;;
|
|
|
|
;;;
|
|
;;; round
|
|
;;;
|
|
|
|
;;;
|
|
;;; exact->inexact
|
|
;;;
|
|
|
|
;;;
|
|
;;; floor
|
|
;;;
|
|
|
|
;;;
|
|
;;; ceiling
|
|
;;;
|
|
|
|
;;;
|
|
;;; make-rectangular
|
|
;;;
|
|
|
|
;;;
|
|
;;; make-polar
|
|
;;;
|
|
|
|
;;;
|
|
;;; real-part
|
|
;;;
|
|
|
|
;;;
|
|
;;; imag-part
|
|
;;;
|
|
|
|
;;;
|
|
;;; magnitude
|
|
;;;
|
|
|
|
;;;
|
|
;;; angle
|
|
;;;
|
|
|
|
;;;
|
|
;;; inexact->exact
|
|
;;;
|