Skip to content

Commit 84fc536

Browse files
committed
Remove complex number type
1 parent b1fb6ae commit 84fc536

File tree

6 files changed

+6
-28
lines changed

6 files changed

+6
-28
lines changed

auto_editor/cmds/test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -560,15 +560,12 @@ def cases(*cases: tuple[str, object]) -> None:
560560
("238.5", 238.5),
561561
("-34", -34),
562562
("-98.3", -98.3),
563-
("+3i", 3j),
564563
("3sec", 90),
565564
("-3sec", -90),
566565
("0.2sec", 6),
567566
("(+ 4 3)", 7),
568567
("(+ 4 3 2)", 9),
569568
("(+ 10.5 3)", 13.5),
570-
("(+ 3+4i -2-2i)", 1 + 2j),
571-
("(+ 3+4i -2-2i 5)", 6 + 2j),
572569
("(- 4 3)", 1),
573570
("(- 3)", -3),
574571
("(- 10.5 3)", 7.5),
@@ -591,7 +588,6 @@ def cases(*cases: tuple[str, object]) -> None:
591588
("(int? #t)", False),
592589
("(int? #f)", False),
593590
("(int? 4/5)", False),
594-
("(int? 0+2i)", False),
595591
('(int? "hello")', False),
596592
('(int? "3")', False),
597593
("(float? -23.4)", True),
@@ -605,7 +601,6 @@ def cases(*cases: tuple[str, object]) -> None:
605601
('(define apple "Red Wood") apple', "Red Wood"),
606602
("(= 1 1.0)", True),
607603
("(= 1 2)", False),
608-
("(= 2+3i 2+3i 2+3i)", True),
609604
("(= 1)", True),
610605
("(+)", 0),
611606
("(*)", 1),
@@ -614,7 +609,6 @@ def cases(*cases: tuple[str, object]) -> None:
614609
('(if #f mango "Hi")', "Hi"),
615610
('{if (= [+ 3 4] 7) "yes" "no"}', "yes"),
616611
("((if #t + -) 3 4)", 7),
617-
("((if #t + oops) 3+3i 4-2i)", 7 + 1j),
618612
("((if #f + -) 3 4)", -1),
619613
("(when (positive? 3) 17)", 17),
620614
("(string)", ""),

auto_editor/lang/palet.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def number(self) -> Token:
148148
token = SEC
149149
elif unit == "dB":
150150
token = DB
151-
elif unit != "i" and unit != "%":
151+
elif unit != "%":
152152
return Token(
153153
VAL,
154154
Sym(result + unit, self.lineno, self.column),
@@ -157,9 +157,7 @@ def number(self) -> Token:
157157
)
158158

159159
try:
160-
if unit == "i":
161-
return Token(VAL, complex(result + "j"), self.lineno, self.column)
162-
elif unit == "%":
160+
if unit == "%":
163161
return Token(VAL, float(result) / 100, self.lineno, self.column)
164162
elif "/" in result:
165163
return Token(token, Fraction(result), self.lineno, self.column)

auto_editor/lang/stdenv.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import numpy as np
2020
from numpy.typing import NDArray
2121

22-
Number = int | float | complex | Fraction
22+
Number = int | float | Fraction
2323
BoolList = NDArray[np.bool_]
2424
Node = tuple
2525

@@ -835,9 +835,6 @@ def _xor(*vals: Any) -> bool | BoolList:
835835
return reduce(lambda a, b: a ^ b, vals)
836836

837837
def number_to_string(val: Number) -> str:
838-
if isinstance(val, complex):
839-
join = "" if val.imag < 0 else "+"
840-
return f"{val.real}{join}{val.imag}i"
841838
return f"{val}"
842839

843840
def string_to_number(val) -> float:
@@ -989,7 +986,6 @@ def change_file_ext(a: str, ext: str) -> str:
989986
"int?": is_int,
990987
"float?": is_float,
991988
"frac?": is_frac,
992-
"complex?": Contract("complex?", lambda v: type(v) is complex),
993989
"nat?": is_nat,
994990
"nat1?": is_nat1,
995991
"threshold?": is_threshold,
@@ -1044,8 +1040,6 @@ def change_file_ext(a: str, ext: str) -> str:
10441040
"div": Proc("div", int_div, (2, None), is_int),
10451041
"add1": Proc("add1", lambda z: z + 1, (1, 1), is_num),
10461042
"sub1": Proc("sub1", lambda z: z - 1, (1, 1), is_num),
1047-
"real-part": Proc("real-part", lambda v: v.real, (1, 1), is_num),
1048-
"imag-part": Proc("imag-part", lambda v: v.imag, (1, 1), is_num),
10491043
# reals
10501044
"pow": Proc("pow", pow, (2, 2), is_real),
10511045
"abs": Proc("abs", abs, (1, 1), is_real),

auto_editor/lib/contracts.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def check_contract(c: object, val: object) -> bool:
4646
return val is True
4747
if c is False:
4848
return val is False
49-
if type(c) in (int, float, float64, Fraction, complex, str, Sym):
49+
if type(c) in (int, float, float64, Fraction, str, Sym):
5050
return val == c
5151
raise MyError(f"Invalid contract, got: {print_str(c)}")
5252

@@ -164,18 +164,16 @@ def is_contract(c: object) -> bool:
164164
return True
165165
if c is True or c is False:
166166
return True
167-
return type(c) in (int, float, Fraction, complex, str, Sym)
167+
return type(c) in (int, float, Fraction, str, Sym)
168168

169169

170170
is_bool = Contract("bool?", lambda v: type(v) is bool)
171171
is_int = Contract("int?", lambda v: type(v) is int)
172172
is_nat = Contract("nat?", lambda v: type(v) is int and v > -1)
173173
is_nat1 = Contract("nat1?", lambda v: type(v) is int and v > 0)
174174
int_not_zero = Contract("(or/c (not/c 0) int?)", lambda v: v != 0 and is_int(v))
175-
is_num = Contract(
176-
"number?", lambda v: type(v) in (int, float, float64, Fraction, complex)
177-
)
178175
is_real = Contract("real?", lambda v: type(v) in (int, float, float64, Fraction))
176+
is_num = is_real
179177
is_float = Contract("float?", lambda v: type(v) in (float, float64))
180178
is_frac = Contract("frac?", lambda v: type(v) is Fraction)
181179
is_str = Contract("string?", lambda v: type(v) is str)

auto_editor/lib/data_structs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ def display_str(val: object) -> str:
182182
return f"{val}"
183183
if type(val) is range:
184184
return "#<range>"
185-
if type(val) is complex:
186-
join = "" if val.imag < 0 else "+"
187-
return f"{val.real}{join}{val.imag}i"
188185
if type(val) is np.bool_:
189186
return "1" if val else "0"
190187
if type(val) is np.float64 or type(val) is np.float32:

docs/doc.pal

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@
283283
(pred "frac?"
284284
(text "Returns "#t" if "'v" is a fraction (a rational number), "#f" otherwise.")
285285
)
286-
(pred "complex?" (text "Returns "#t" if "'v" is an complex number, "#f" otherwise."))
287286
(pred "nat?"
288287
(text "Returns "#t" if "'v" is an integer and "'v" is >= 0, "#f" otherwise.")
289288
)
@@ -358,8 +357,6 @@
358357
(proc "abs" '((x real?) real?) (text "Returns the absolute value of "'x"."))
359358
(proc "max" '((x real?) ... real?) (text "Returns largest value of the "'x"s."))
360359
(proc "min" '((x real?) ... real?) (text "Returns smallest value of the "'x"s."))
361-
(proc "real-part" '((z number?) real?) (text "Returns the real part of "'z"."))
362-
(proc "imag-part" '((z number?) real?) (text "Returns the imaginary part of "'z"."))
363360
(proc "round" '((x real?) int?)
364361
(text
365362
"Returns the closest integer to "'x" resolving ties in favor of even numbers."

0 commit comments

Comments
 (0)