* Added abs.
This commit is contained in:
parent
973595a93f
commit
0c62d5bee8
BIN
src/ikarus.boot
BIN
src/ikarus.boot
Binary file not shown.
|
@ -118,6 +118,7 @@
|
||||||
modulo even? odd?
|
modulo even? odd?
|
||||||
positive? expt gcd lcm numerator denominator exact-integer-sqrt
|
positive? 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
|
||||||
exact->inexact floor ceiling round log fl=? fl<? fl<=? fl>?
|
exact->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?)
|
||||||
(import
|
(import
|
||||||
|
@ -132,7 +133,7 @@
|
||||||
remainder modulo even? odd? quotient+remainder number->string positive?
|
remainder modulo even? odd? quotient+remainder number->string positive?
|
||||||
string->number expt gcd lcm numerator denominator
|
string->number expt gcd lcm numerator denominator
|
||||||
exact->inexact floor ceiling round log
|
exact->inexact floor ceiling round log
|
||||||
exact-integer-sqrt min max
|
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?))
|
||||||
|
|
||||||
|
@ -869,6 +870,22 @@
|
||||||
x
|
x
|
||||||
(error 'min "~s is not a number" x))]))
|
(error 'min "~s is not a number" x))]))
|
||||||
|
|
||||||
|
(define (abs x)
|
||||||
|
(cond
|
||||||
|
[(fixnum? x)
|
||||||
|
(if ($fx< x 0) (- x) x)]
|
||||||
|
[(bignum? x)
|
||||||
|
(if ($bignum-positive? x) x (- x))]
|
||||||
|
[(flonum? x)
|
||||||
|
(if ($flnegative? x)
|
||||||
|
($fl* x (exact->inexact -1))
|
||||||
|
x)]
|
||||||
|
[(ratnum? x)
|
||||||
|
(let ([n ($ratnum-n x)])
|
||||||
|
(if (< n 0)
|
||||||
|
($make-ratnum (- n) ($ratnum-d x))
|
||||||
|
x))]
|
||||||
|
[else (error 'abs "~s is not a number" x)]))
|
||||||
|
|
||||||
(define flmin
|
(define flmin
|
||||||
(case-lambda
|
(case-lambda
|
||||||
|
|
|
@ -416,6 +416,7 @@
|
||||||
[lcm i r]
|
[lcm i r]
|
||||||
[max i r]
|
[max i r]
|
||||||
[min i r]
|
[min i r]
|
||||||
|
[abs i r]
|
||||||
[log i r]
|
[log i r]
|
||||||
[numerator i r]
|
[numerator i r]
|
||||||
[denominator i r]
|
[denominator i r]
|
||||||
|
|
Loading…
Reference in New Issue