diff --git a/R6RS-TODO.txt b/R6RS-TODO.txt index c47fd9f..3b79421 100644 --- a/R6RS-TODO.txt +++ b/R6RS-TODO.txt @@ -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 diff --git a/src/ikarus.boot b/src/ikarus.boot index e4a2bf5..c64bf48 100644 Binary files a/src/ikarus.boot and b/src/ikarus.boot differ diff --git a/src/ikarus.numerics.ss b/src/ikarus.numerics.ss index 7d81a1e..665c1d2 100644 --- a/src/ikarus.numerics.ss +++ b/src/ikarus.numerics.ss @@ -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) diff --git a/src/makefile.ss b/src/makefile.ss index 42aba4b..05b4554 100755 --- a/src/makefile.ss +++ b/src/makefile.ss @@ -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]