* Added truncate and fltruncate
This commit is contained in:
parent
79b6e46cab
commit
e8f05ac4b7
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -297,7 +297,7 @@
|
||||||
modulo even? odd?
|
modulo even? odd?
|
||||||
positive? negative? expt gcd lcm numerator denominator exact-integer-sqrt
|
positive? negative? expt gcd lcm numerator denominator exact-integer-sqrt
|
||||||
quotient+remainder number->string string->number min max
|
quotient+remainder number->string string->number min max
|
||||||
abs
|
abs truncate fltruncate
|
||||||
exact->inexact inexact floor ceiling round log fl=? fl<? fl<=? fl>?
|
exact->inexact inexact floor ceiling round log fl=? fl<? fl<=? fl>?
|
||||||
fl>=? fl+ fl- fl* fl/ flsqrt flmin flzero? flnegative?
|
fl>=? fl+ fl- fl* fl/ flsqrt flmin flzero? flnegative?
|
||||||
sin cos tan asin acos atan sqrt
|
sin cos tan asin acos atan sqrt
|
||||||
|
@ -318,7 +318,7 @@
|
||||||
exact-integer-sqrt min max abs
|
exact-integer-sqrt min max abs
|
||||||
fl=? fl<? fl<=? fl>? fl>=? fl+ fl- fl* fl/ flsqrt flmin
|
fl=? fl<? fl<=? fl>? fl>=? fl+ fl- fl* fl/ flsqrt flmin
|
||||||
flzero? flnegative?
|
flzero? flnegative?
|
||||||
sin cos tan asin acos atan sqrt
|
sin cos tan asin acos atan sqrt truncate fltruncate
|
||||||
flround flmax random))
|
flround flmax random))
|
||||||
|
|
||||||
; (foreign-call "ikrt_fixnum_to_flonum" x))
|
; (foreign-call "ikrt_fixnum_to_flonum" x))
|
||||||
|
@ -1857,6 +1857,11 @@
|
||||||
[else
|
[else
|
||||||
(if (even? q) q (- q 1))])))))))
|
(if (even? q) q (- q 1))])))))))
|
||||||
|
|
||||||
|
|
||||||
|
(define ($ratnum-truncate x)
|
||||||
|
(let ([n ($ratnum-n x)] [d ($ratnum-d x)])
|
||||||
|
(quotient n d)))
|
||||||
|
|
||||||
;(define ($flround x)
|
;(define ($flround x)
|
||||||
; (foreign-call "ikrt_fl_round" x ($make-flonum)))
|
; (foreign-call "ikrt_fl_round" x ($make-flonum)))
|
||||||
|
|
||||||
|
@ -1874,8 +1879,6 @@
|
||||||
[else x]))
|
[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)
|
[(flonum? x)
|
||||||
|
@ -1888,6 +1891,26 @@
|
||||||
[(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)]))
|
||||||
|
|
||||||
|
(define (truncate x)
|
||||||
|
(cond
|
||||||
|
[(flonum? x)
|
||||||
|
(let ([e (or ($flonum->exact x)
|
||||||
|
(error 'truncate "~s has no real value" x))])
|
||||||
|
(cond
|
||||||
|
[(ratnum? e) (exact->inexact ($ratnum-truncate e))]
|
||||||
|
[else x]))]
|
||||||
|
[(ratnum? x) ($ratnum-truncate x)]
|
||||||
|
[(or (fixnum? x) (bignum? x)) x]
|
||||||
|
[else (error 'truncate "~s is not a number" x)]))
|
||||||
|
|
||||||
|
(define (fltruncate x)
|
||||||
|
(unless (flonum? x)
|
||||||
|
(error 'fltruncate "~s is not a flonum" x))
|
||||||
|
(let ([v ($flonum->exact x)])
|
||||||
|
(cond
|
||||||
|
[(ratnum? v) (exact->inexact ($ratnum-truncate x))]
|
||||||
|
[else x])))
|
||||||
|
|
||||||
(define log
|
(define log
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(cond
|
(cond
|
||||||
|
|
|
@ -478,6 +478,7 @@
|
||||||
[flfloor i rfl]
|
[flfloor i rfl]
|
||||||
[flround i rfl]
|
[flround i rfl]
|
||||||
[flceiling i rfl]
|
[flceiling i rfl]
|
||||||
|
[fltruncate i rfl]
|
||||||
[flnumerator i rfl]
|
[flnumerator i rfl]
|
||||||
[fldenominator i rfl]
|
[fldenominator i rfl]
|
||||||
[flexp i rfl]
|
[flexp i rfl]
|
||||||
|
@ -543,6 +544,7 @@
|
||||||
[floor i r]
|
[floor i r]
|
||||||
[ceiling i r]
|
[ceiling i r]
|
||||||
[round i r]
|
[round i r]
|
||||||
|
[truncate i r]
|
||||||
[exact-integer-sqrt i r]
|
[exact-integer-sqrt i r]
|
||||||
[exact->inexact i r]
|
[exact->inexact i r]
|
||||||
[inexact->exact i r]
|
[inexact->exact i r]
|
||||||
|
|
|
@ -220,7 +220,7 @@
|
||||||
[symbol=? C ba]
|
[symbol=? C ba]
|
||||||
[symbol? C ba se]
|
[symbol? C ba se]
|
||||||
[tan C ba se]
|
[tan C ba se]
|
||||||
[truncate S ba se]
|
[truncate C ba se]
|
||||||
[values C ba se]
|
[values C ba se]
|
||||||
[vector C ba se]
|
[vector C ba se]
|
||||||
[vector->list C ba se]
|
[vector->list C ba se]
|
||||||
|
@ -341,7 +341,7 @@
|
||||||
[flsin C fl]
|
[flsin C fl]
|
||||||
[flsqrt C fl]
|
[flsqrt C fl]
|
||||||
[fltan C fl]
|
[fltan C fl]
|
||||||
[fltruncate S fl]
|
[fltruncate C fl]
|
||||||
[flzero? C fl]
|
[flzero? C fl]
|
||||||
[real->flonum D fl]
|
[real->flonum D fl]
|
||||||
[make-no-infinities-violation D fl]
|
[make-no-infinities-violation D fl]
|
||||||
|
|
Loading…
Reference in New Issue