From 1b7774eec8ab3d94cd1b2e3d1ab18cf25818a69f Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Thu, 14 Nov 2013 17:51:57 +0900 Subject: [PATCH] add some missing function listed in section 6.2. Numbers --- README.md | 2 +- piclib/built-in.scm | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bddad76..eab4e402 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ | 6.2.3 Implementation restrictions | yes | | | 6.2.4 Implementation extensions | yes | | | 6.2.5 Syntax of numerical constants | yes | | -| 6.2.6 Numerical operations | yes | some functions that return multiple values are not supported for now. Also, picrin does not provide complex library procedures. | +| 6.2.6 Numerical operations | yes | `denominator`, `numerator`, and `rationalize` are not supported for now. Also, picrin does not provide complex library procedures. | | 6.2.7 Numerical input and output | no | | | 6.3 Booleans | yes | | | 6.4 Pairs and lists | yes | | diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 9eb4d8a4..f964edcf 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -272,6 +272,20 @@ (car (cddr x)))) bindings)))))) +;;; 6.2. Numbers + +(define (floor/ n m) + (values (floor-quotient n m) + (floor-remainder n m))) + +(define (truncate/ n m) + (values (truncate-quotient n m) + (truncate-remainder n m))) + +(define (exact-integer-sqrt k) + (let ((n (exact (sqrt k)))) + (values n (- k (square n))))) + (define (boolean=? . objs) (define (every pred list) (if (null? list)