mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-11 23:07:36 +02:00
Issue #55 - parse out read and imag for complex
This commit is contained in:
parent
9e17ea628b
commit
c480470123
1 changed files with 14 additions and 4 deletions
|
@ -175,17 +175,27 @@
|
||||||
((string? t) ;; Special case: complex number
|
((string? t) ;; Special case: complex number
|
||||||
(let* ((end (vector-ref token 1))
|
(let* ((end (vector-ref token 1))
|
||||||
(len (string-length t))
|
(len (string-length t))
|
||||||
|
(only-imag? (= (+ 1 end) len)) ;; EG: "57i" with no real component
|
||||||
|
(real-str (if only-imag?
|
||||||
|
"0"
|
||||||
|
(substring t 0 end)))
|
||||||
|
(imag-str (if only-imag?
|
||||||
|
(substring t 0 end)
|
||||||
|
(substring t end (- len 1))))
|
||||||
|
(real (string->number real-str))
|
||||||
|
(imag (string->number imag-str))
|
||||||
)
|
)
|
||||||
(if (= (+ 1 end) len)
|
#;(if (= (+ 1 end) len)
|
||||||
(let ((real "0")
|
(let ((real "0")
|
||||||
(imag (substring t 0 end))) ;; Only an imag part
|
(imag (substring t 0 end))) ;; Only an imag part
|
||||||
(write `(DEBUG ,t ,end ,len real ,(string->number real) imag ,(string->number imag))))
|
(write `(DEBUG ,t ,end ,len real ,(string->number real) imag ,(string->number imag))))
|
||||||
(let ((real (substring t 0 end))
|
(let ((real (substring t 0 end))
|
||||||
(imag (substring t (+ 1 end) (- len 1))))
|
(imag (substring t end (- len 1))))
|
||||||
(if (= 0 (string-length imag))
|
(if (= 0 (string-length imag))
|
||||||
(set! imag "1"))
|
(set! imag "1"))
|
||||||
(write `(DEBUG ,t ,end ,len real ,(string->number real) imag ,(string->number imag))))))
|
(write `(DEBUG ,t ,end ,len real ,(string->number real) imag ,(string->number imag)))))
|
||||||
t)
|
;; TODO: actually do (make-rectangular real imag) or equivalent, instead of this debug result:
|
||||||
|
(list t only-imag? end real imag)))
|
||||||
(else
|
(else
|
||||||
(error "Unexpected token" t)))))
|
(error "Unexpected token" t)))))
|
||||||
((= (vector-length token) 1) ;; Special case: error
|
((= (vector-length token) 1) ;; Special case: error
|
||||||
|
|
Loading…
Add table
Reference in a new issue