From 489535e156c9b8a9f39af6dbc89c45550225e098 Mon Sep 17 00:00:00 2001 From: "Sunrim KIM (keen)" <3han5chou7@gmail.com> Date: Thu, 18 Sep 2014 23:26:07 +0900 Subject: [PATCH] let `min` and `max` preserve exactness --- piclib/scheme/base.scm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/piclib/scheme/base.scm b/piclib/scheme/base.scm index a5e4bc67..9a142113 100644 --- a/piclib/scheme/base.scm +++ b/piclib/scheme/base.scm @@ -201,18 +201,18 @@ (define (min . args) (define (min a b) (if (< a b) a b)) - (let loop ((args args) (acc +inf.0)) + (let loop ((args args) (acc +inf.0) (exactp #t)) (if (null? args) - acc - (loop (cdr args) (min (car args) acc))))) + (if exactp acc (inexact acc)) + (loop (cdr args) (min (car args) acc) (and (exact? (car args)) exactp))))) (define (max . args) (define (max a b) (if (> a b) a b)) - (let loop ((args args) (acc -inf.0)) + (let loop ((args args) (acc -inf.0) (exactp #t)) (if (null? args) - acc - (loop (cdr args) (max (car args) acc))))) + (if exactp acc (inexact acc)) + (loop (cdr args) (max (car args) acc) (and (exact? (car args)) exactp))))) (define (floor-quotient i j) (call-with-values (lambda () (floor/ i j))