* Added numerator and denominator.

This commit is contained in:
Abdulaziz Ghuloum 2007-05-21 19:54:36 -04:00
parent b1a6668060
commit 9f1e3dcb0b
4 changed files with 17 additions and 3 deletions

View File

@ -18,7 +18,6 @@ TODO for (R6RS BASE)
- Make sure the following primitives work:
rationalize
numerator denominator
make-rectangular make-polar
real-part imag-part
@ -87,3 +86,4 @@ TODO for (R6RS BASE)
Completed for (R6RS BASE):
numerator denominator

Binary file not shown.

View File

@ -28,7 +28,7 @@
(library (ikarus generic-arithmetic)
(export + - * / zero? = < <= > >= add1 sub1 quotient remainder
positive? expt gcd lcm
positive? expt gcd lcm numerator denominator
quotient+remainder number->string string->number)
(import
(ikarus system $fx)
@ -38,7 +38,7 @@
(ikarus system $strings)
(except (ikarus) + - * / zero? = < <= > >= add1 sub1 quotient
remainder quotient+remainder number->string positive?
string->number expt gcd lcm))
string->number expt gcd lcm numerator denominator))
(define (fixnum->flonum x)
(foreign-call "ikrt_fixnum_to_flonum" x))
@ -1023,7 +1023,19 @@
[(fixnum? x) (foreign-call "ikrt_fx_sqrt" x)]
[else (error 'sqrt "unsupported ~s" x)])))
(define numerator
(lambda (x)
(cond
[(ratnum? x) ($ratnum-n x)]
[(or (fixnum? x) (bignum? x)) x]
[else (error 'numerator "~s is not an exact integer" x)])))
(define denominator
(lambda (x)
(cond
[(ratnum? x) ($ratnum-d x)]
[(or (fixnum? x) (bignum? x)) 1]
[else (error 'denominator "~s is not an exact integer" x)])))
(define string->number
(lambda (x)

View File

@ -381,6 +381,8 @@
[flonum->string i]
[gcd i r]
[lcm i r]
[numerator i r]
[denominator i r]
[symbol? i r symbols]
[gensym? i symbols]
[gensym i symbols]