Skip to content

Commit 55aeeed

Browse files
committed
Implement abs for complex
1 parent 13be384 commit 55aeeed

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/runtime/lpython_builtin.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,19 @@ def abs(b: bool) -> i32:
6464

6565
@overload
6666
def abs(c: c32) -> f32:
67-
pass
67+
a: f32
68+
b: f32
69+
a = c.real
70+
b = _lfortran_caimag(c)
71+
return (a**2 + b**2)**(1/2)
6872

6973
@overload
7074
def abs(c: c64) -> f64:
71-
pass
75+
a: f64
76+
b: f64
77+
a = c.real
78+
b = _lfortran_zaimag(c)
79+
return (a**2 + b**2)**(1/2)
7280

7381

7482
def str(x: i32) -> str:

0 commit comments

Comments
 (0)