Add numerator->exact and denominator->exact.
authorJoe Marshall <eval.apply@gmail.com>
Thu, 24 Mar 2011 20:48:13 +0000 (13:48 -0700)
committerJoe Marshall <eval.apply@gmail.com>
Thu, 24 Mar 2011 20:48:13 +0000 (13:48 -0700)
src/runtime/arith.scm
src/runtime/runtime.pkg

index da78fef88a658204cfbfbe55758b744fb1a744bf..9944779a9ac57650878e1d5e645dfbdc47659a52 100644 (file)
@@ -1159,6 +1159,18 @@ USA.
 
 (define-rational-unary real:numerator rat:numerator)
 (define-rational-unary real:denominator rat:denominator)
+
+(define-syntax define-rational-exact-unary
+  (sc-macro-transformer
+   (lambda (form environment)
+     (let ((operator (close-syntax (list-ref form 2) environment)))
+       `(DEFINE (,(list-ref form 1) Q)
+         (IF (FLONUM? Q)
+             (,operator (FLO:->RATIONAL Q))
+             (,operator Q)))))))
+
+(define-rational-exact-unary real:numerator->exact rat:numerator)
+(define-rational-exact-unary real:denominator->exact rat:denominator)
 \f
 (define-syntax define-transcendental-unary
   (sc-macro-transformer
@@ -1522,6 +1534,12 @@ USA.
 
 (define (complex:denominator q)
   (real:denominator (complex:real-arg 'DENOMINATOR q)))
+
+(define (complex:numerator->exact q)
+  (real:numerator->exact (complex:real-arg 'NUMERATOR->EXACT q)))
+
+(define (complex:denominator->exact q)
+  (real:denominator->exact (complex:real-arg 'DENOMINATOR->EXACT q)))
 \f
 (define (complex:floor x)
   (if (recnum? x)
index 9b5525cfbb0daa256c4911a57a78fa45fa9f0043..836b5c91a3323cefb6c8b7254bc95019eb58f72c 100644 (file)
@@ -2817,6 +2817,7 @@ USA.
          (conjugate complex:conjugate)
          (cos complex:cos)
          (denominator complex:denominator)
+         (denominator->exact complex:denominator->exact)
          (even? complex:even?)
          (exact->inexact complex:exact->inexact)
          (exact-rational? rat:rational?)
@@ -2840,6 +2841,7 @@ USA.
          (negative? complex:negative?)
          (number? complex:complex?)
          (numerator complex:numerator)
+         (numerator->exact complex:numerator->exact)
          (positive? complex:positive?)
          (rational? complex:rational?)
          (rationalize complex:rationalize)