* Added flceiling, flfloor, and fixed rounding bug in flround and
round
This commit is contained in:
parent
cb94cf88b2
commit
1c86a105c5
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -10,6 +10,7 @@
|
||||||
inexact->exact exact $flonum-rational? $flonum-integer? $flzero?
|
inexact->exact exact $flonum-rational? $flonum-integer? $flzero?
|
||||||
$flnegative? flpositive? flabs fixnum->flonum
|
$flnegative? flpositive? flabs fixnum->flonum
|
||||||
flsin flcos fltan flasin flacos flatan fleven? flodd?
|
flsin flcos fltan flasin flacos flatan fleven? flodd?
|
||||||
|
flfloor flceiling
|
||||||
flinteger? flonum-bytes flnan? flfinite? flinfinite?)
|
flinteger? flonum-bytes flnan? flfinite? flinfinite?)
|
||||||
(import
|
(import
|
||||||
(ikarus system $bytevectors)
|
(ikarus system $bytevectors)
|
||||||
|
@ -19,6 +20,7 @@
|
||||||
$flonum-rational? $flonum-integer?)
|
$flonum-rational? $flonum-integer?)
|
||||||
(except (ikarus) inexact->exact exact flpositive? flabs fixnum->flonum
|
(except (ikarus) inexact->exact exact flpositive? flabs fixnum->flonum
|
||||||
flsin flcos fltan flasin flacos flatan fleven? flodd?
|
flsin flcos fltan flasin flacos flatan fleven? flodd?
|
||||||
|
flfloor flceiling
|
||||||
flinteger? flonum-parts flonum-bytes flnan? flfinite? flinfinite?))
|
flinteger? flonum-parts flonum-bytes flnan? flfinite? flinfinite?))
|
||||||
|
|
||||||
(define (flonum-bytes f)
|
(define (flonum-bytes f)
|
||||||
|
@ -227,10 +229,38 @@
|
||||||
(if (flonum? x)
|
(if (flonum? x)
|
||||||
(foreign-call "ikrt_fl_atan" x)
|
(foreign-call "ikrt_fl_atan" x)
|
||||||
(error 'flatan "~s is not a flonum" x)))
|
(error 'flatan "~s is not a flonum" x)))
|
||||||
|
|
||||||
|
|
||||||
|
(define (flfloor x)
|
||||||
|
(define (ratnum-floor x)
|
||||||
|
(let ([n (numerator x)] [d (denominator x)])
|
||||||
|
(let ([q (quotient n d)])
|
||||||
|
(if (>= n 0) q (- q 1)))))
|
||||||
|
(cond
|
||||||
|
[(flonum? x)
|
||||||
|
(let ([e ($flonum->exact x)])
|
||||||
|
(cond
|
||||||
|
[(ratnum? e)
|
||||||
|
(exact->inexact (ratnum-floor e))]
|
||||||
|
[else x]))]
|
||||||
|
[else (error 'flfloor "~s is not a flonum" x)]))
|
||||||
|
|
||||||
|
(define (flceiling x)
|
||||||
|
(cond
|
||||||
|
[(flonum? x)
|
||||||
|
(let ([e ($flonum->exact x)])
|
||||||
|
(cond
|
||||||
|
[(ratnum? e)
|
||||||
|
(exact->inexact (ceiling e))]
|
||||||
|
[else x]))]
|
||||||
|
[else (error 'flceiling "~s is not a flonum" x)]))
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(library (ikarus generic-arithmetic)
|
(library (ikarus generic-arithmetic)
|
||||||
(export + - * / zero? = < <= > >= add1 sub1 quotient remainder
|
(export + - * / zero? = < <= > >= add1 sub1 quotient remainder
|
||||||
modulo even? odd?
|
modulo even? odd?
|
||||||
|
@ -1796,8 +1826,8 @@
|
||||||
[else
|
[else
|
||||||
(if (even? q) q (- q 1))])))))))
|
(if (even? q) q (- q 1))])))))))
|
||||||
|
|
||||||
(define ($flround x)
|
;(define ($flround x)
|
||||||
(foreign-call "ikrt_fl_round" x ($make-flonum)))
|
; (foreign-call "ikrt_fl_round" x ($make-flonum)))
|
||||||
|
|
||||||
; (let ([e ($flonum->exact x)])
|
; (let ([e ($flonum->exact x)])
|
||||||
; (cond
|
; (cond
|
||||||
|
@ -1807,12 +1837,20 @@
|
||||||
|
|
||||||
(define (flround x)
|
(define (flround x)
|
||||||
(if (flonum? x)
|
(if (flonum? x)
|
||||||
($flround x)
|
(let ([e ($flonum->exact x)])
|
||||||
|
(cond
|
||||||
|
[(ratnum? e) (exact->inexact ($ratnum-round e))]
|
||||||
|
[else x]))
|
||||||
(error 'flround "~s is not a flonum" x)))
|
(error 'flround "~s is not a flonum" x)))
|
||||||
|
|
||||||
(define (round x)
|
(define (round x)
|
||||||
(cond
|
(cond
|
||||||
[(flonum? x) ($flround x)]
|
[(flonum? x)
|
||||||
|
(let ([e (or ($flonum->exact x)
|
||||||
|
(error 'round "~s has no real value" x))])
|
||||||
|
(cond
|
||||||
|
[(ratnum? e) (exact->inexact ($ratnum-round e))]
|
||||||
|
[else x]))]
|
||||||
[(ratnum? x) ($ratnum-round x)]
|
[(ratnum? x) ($ratnum-round x)]
|
||||||
[(or (fixnum? x) (bignum? x)) x]
|
[(or (fixnum? x) (bignum? x)) x]
|
||||||
[else (error 'round "~s is not a number" x)]))
|
[else (error 'round "~s is not a number" x)]))
|
||||||
|
|
|
@ -469,13 +469,15 @@
|
||||||
[flpositive? i rfl]
|
[flpositive? i rfl]
|
||||||
[flabs i rfl]
|
[flabs i rfl]
|
||||||
[flmax i rfl]
|
[flmax i rfl]
|
||||||
[flround i rfl]
|
|
||||||
[flsin i rfl]
|
[flsin i rfl]
|
||||||
[flcos i rfl]
|
[flcos i rfl]
|
||||||
[fltan i rfl]
|
[fltan i rfl]
|
||||||
[flasin i rfl]
|
[flasin i rfl]
|
||||||
[flacos i rfl]
|
[flacos i rfl]
|
||||||
[flatan i rfl]
|
[flatan i rfl]
|
||||||
|
[flfloor i rfl]
|
||||||
|
[flround i rfl]
|
||||||
|
[flceiling i rfl]
|
||||||
[fixnum->string i]
|
[fixnum->string i]
|
||||||
[string->flonum i]
|
[string->flonum i]
|
||||||
[- i r]
|
[- i r]
|
||||||
|
|
|
@ -312,7 +312,7 @@
|
||||||
[flacos C fl]
|
[flacos C fl]
|
||||||
[flasin C fl]
|
[flasin C fl]
|
||||||
[flatan C fl]
|
[flatan C fl]
|
||||||
[flceiling S fl]
|
[flceiling C fl]
|
||||||
[flcos C fl]
|
[flcos C fl]
|
||||||
[fldenominator S fl]
|
[fldenominator S fl]
|
||||||
[fldiv S fl]
|
[fldiv S fl]
|
||||||
|
@ -323,7 +323,7 @@
|
||||||
[flexp S fl]
|
[flexp S fl]
|
||||||
[flexpt S fl]
|
[flexpt S fl]
|
||||||
[flfinite? C fl]
|
[flfinite? C fl]
|
||||||
[flfloor S fl]
|
[flfloor C fl]
|
||||||
[flinfinite? C fl]
|
[flinfinite? C fl]
|
||||||
[flinteger? C fl]
|
[flinteger? C fl]
|
||||||
[fllog S fl]
|
[fllog S fl]
|
||||||
|
|
Loading…
Reference in New Issue