Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[WIP] complex numbers #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions racketscript-compiler/racketscript/compiler/assembler.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@
[+nan.0 (emit "NaN")]
[+nan.f (emit "NaN")]
[_ #:when (single-flonum? v) (emit (~a (exact->inexact (inexact->exact v))))]
[_ #:when (zero? v) (emit (~a 0))]
[_ (emit (~a v))])] ;; TODO
[(boolean? v) (emit (if v "true" "false"))]
[(void? v)
Expand Down
5 changes: 5 additions & 0 deletions racketscript-compiler/racketscript/compiler/transform.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@
(void? d)
(real? d))
(ILValue d)]
[(and (number? d) (zero? d)) (ILValue d)] ; some zero values are not real, eg 0.0+0.0i
[(and (number? d) (not (real? d))) ;; FIXME with real complex num implementation
(ILApp (name-in-module 'core 'Pair.make)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Complex type be a class, so that we can differentiate b/w complex and pair of reals.

(list (ILValue (real-part d))
(ILValue (imag-part d))))]
[else (error (~a "unsupported value" d))]))

(: expand-normal-case-lambda (-> (Listof PlainLambda)
Expand Down
13 changes: 13 additions & 0 deletions tests/basic/complex.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#lang racket/base

;; zeros
(displayln 0+0i) ; prints as 0
; (displayln 0+0.0i) ; prints as 0.0+0.0i
(when (zero? 0+0.0i)
(displayln 0))
; (displayln 0.0+0i) ; prints as 0.0
(when (zero? 0.0+0i)
(displayln 0))
; (displayln 0.0+0.0i) ; prints as 0.0+0.0i
(when (zero? 0.0+0.0i)
(displayln 0))