From a69c9fb665459e2bfdbda1bf80741a0af31a7faf Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:06:40 -0800 Subject: New upstream version 3b5 --- math-integer.scm | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) mode change 100644 => 100755 math-integer.scm (limited to 'math-integer.scm') diff --git a/math-integer.scm b/math-integer.scm old mode 100644 new mode 100755 index 1ce70f8..2a1572a --- a/math-integer.scm +++ b/math-integer.scm @@ -1,5 +1,5 @@ ; "math-integer.scm": mathematical functions restricted to exact integers -; Copyright (C) 2006 Aubrey Jaffer +; Copyright (C) 2006, 2013 Aubrey Jaffer ; ;Permission to copy this software, to modify it, to redistribute it, ;to distribute modified versions, and to use it for any purpose is @@ -95,8 +95,24 @@ (not (zero? n2))) (proc n1 n2) (slib:error name n1 n2)))) -;;@body +;;@args n1 n2 +;;@defunx remainder n1 n2 +;;@defunx modulo n1 n2 ;;are redefined so that they accept only exact-integer arguments. (define quotient (must-be-exact-integer2 'quotient quotient)) (define remainder (must-be-exact-integer2 'remainder remainder)) (define modulo (must-be-exact-integer2 'modulo modulo)) + +;;@args n1 n2 +;;Returns the quotient of @1 and @2 rounded toward even. +;; +;;@example +;;(quotient 3 2) @result{} 1 +;;(round-quotient 3 2) @result{} 2 +;;@end example +(define (round-quotient num den) + (define quo (quotient num den)) + (define rem (remainder num den)) + (if ((if (even? quo) > >=) (abs (* 2 rem)) (abs den)) + (+ quo (if (eq? (negative? num) (negative? den)) 1 -1)) + quo)) -- cgit v1.2.3