mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-22 07:09:18 +02:00
Max and min should coerce to inexact if any argument if inexact.
Fixes issue #178.
This commit is contained in:
parent
4c0bb08996
commit
5f628c8e72
1 changed files with 24 additions and 8 deletions
|
@ -1055,11 +1055,15 @@
|
|||
(define (numerator x)
|
||||
(if (ratio? x)
|
||||
(ratio-numerator x)
|
||||
(if (inexact? x) (ratio-numerator (inexact->exact x)) x)))
|
||||
(if (inexact? x)
|
||||
(exact->inexact (ratio-numerator (inexact->exact x)))
|
||||
x)))
|
||||
(define (denominator x)
|
||||
(if (exact? x)
|
||||
(if (ratio? x) (ratio-denominator x) 1)
|
||||
(if (integer? x) 1 (ratio-denominator (inexact->exact x))))))
|
||||
(if (integer? x)
|
||||
1
|
||||
(exact->inexact (ratio-denominator (inexact->exact x)))))))
|
||||
(else
|
||||
(cond-expand
|
||||
(complex
|
||||
|
@ -1127,16 +1131,28 @@
|
|||
(if (null? ls) x (lp (lcm2 x (car ls)) (cdr ls))))))
|
||||
|
||||
(define (max x . rest)
|
||||
(let lp ((hi x) (ls rest))
|
||||
(define (~max hi ls)
|
||||
(if (null? ls)
|
||||
hi
|
||||
(lp (if (> (car ls) hi) (car ls) hi) (cdr ls)))))
|
||||
(exact->inexact hi)
|
||||
(~max (if (> (car ls) hi) (car ls) hi) (cdr ls))))
|
||||
(if (inexact? x)
|
||||
(~max x rest)
|
||||
(let lp ((hi x) (ls rest))
|
||||
(cond ((null? ls) hi)
|
||||
((inexact? (car ls)) (~max hi ls))
|
||||
(else (lp (if (> (car ls) hi) (car ls) hi) (cdr ls)))))))
|
||||
|
||||
(define (min x . rest)
|
||||
(let lp ((lo x) (ls rest))
|
||||
(define (~min lo ls)
|
||||
(if (null? ls)
|
||||
lo
|
||||
(lp (if (< (car ls) lo) (car ls) lo) (cdr ls)))))
|
||||
(exact->inexact lo)
|
||||
(~min (if (< (car ls) lo) (car ls) lo) (cdr ls))))
|
||||
(if (inexact? x)
|
||||
(~min x rest)
|
||||
(let lp ((lo x) (ls rest))
|
||||
(cond ((null? ls) lo)
|
||||
((inexact? (car ls)) (~min lo ls))
|
||||
(else (lp (if (< (car ls) lo) (car ls) lo) (cdr ls)))))))
|
||||
|
||||
(cond-expand
|
||||
(complex
|
||||
|
|
Loading…
Add table
Reference in a new issue