fasl reader/writer now understands complex numbers.

This commit is contained in:
Abdulaziz Ghuloum 2008-05-21 00:40:42 -07:00
parent 0a6df79e3b
commit 8827b98972
4 changed files with 19 additions and 4 deletions

View File

@ -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))

View File

@ -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)

View File

@ -1 +1 @@
1484
1485

View File

@ -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)))
)