From 8827b98972fdc319c728c73e6a8bee01039b0e16 Mon Sep 17 00:00:00 2001 From: Abdulaziz Ghuloum Date: Wed, 21 May 2008 00:40:42 -0700 Subject: [PATCH] fasl reader/writer now understands complex numbers. --- scheme/ikarus.fasl.ss | 6 ++++++ scheme/ikarus.fasl.write.ss | 7 +++++++ scheme/last-revision | 2 +- scheme/tests/fasl.ss | 8 +++++--- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/scheme/ikarus.fasl.ss b/scheme/ikarus.fasl.ss index aa440f6..c9be5f7 100644 --- a/scheme/ikarus.fasl.ss +++ b/scheme/ikarus.fasl.ss @@ -364,6 +364,12 @@ (let ([x (/ num den)]) (when m (put-mark m x)) x))] + [(#\i) ;;; compnum + (let* ([real (read)] + [imag (read)]) + (let ([x (make-rectangular real imag)]) + (when m (put-mark m x)) + x))] [else (die who "Unexpected char as a fasl object header" h)]))) (read)) diff --git a/scheme/ikarus.fasl.write.ss b/scheme/ikarus.fasl.write.ss index 751e3af..b6d0abe 100644 --- a/scheme/ikarus.fasl.write.ss +++ b/scheme/ikarus.fasl.write.ss @@ -281,6 +281,10 @@ (write-byte ($bignum-byte-ref x i) p) (f (fxadd1 i))))) m] + [(compnum? x) + (put-tag #\i p) + (fasl-write-object (imag-part x) p h + (fasl-write-object (real-part x) p h m))] [else (die 'fasl-write "not fasl-writable" x)]))) (define (write-bytevector x i j p) (unless ($fx= i j) @@ -373,6 +377,9 @@ [(ratnum? x) (make-graph (numerator x) h) (make-graph (denominator x) h)] + [(compnum? x) + (make-graph (real-part x) h) + (make-graph (imag-part x) h)] [else (die 'fasl-write "not fasl-writable" x)])])))) (define fasl-write-to-port (lambda (x port) diff --git a/scheme/last-revision b/scheme/last-revision index bf4a29a..000b173 100644 --- a/scheme/last-revision +++ b/scheme/last-revision @@ -1 +1 @@ -1484 +1485 diff --git a/scheme/tests/fasl.ss b/scheme/tests/fasl.ss index 950914a..8c4cc04 100644 --- a/scheme/tests/fasl.ss +++ b/scheme/tests/fasl.ss @@ -25,8 +25,10 @@ (test 3498798327498723894789237489324) (test -3498798327498723894789237489324) (test 2389478923749872389723894/23498739874892379482374) - (test -2389478923749872389723894/23498739874892379482374))) - - + (test -2389478923749872389723894/23498739874892379482374) + (test 127487384734.4) + (test (make-rectangular 12 13))) + +)