8000 Expand acronyms for abs, n, etc. · runtimehub-com/algorithms-mojo@8e7a3ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e7a3ff

Browse files
committed
Expand acronyms for abs, n, etc.
1 parent c5c8722 commit 8e7a3ff

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

maths/abs.mojo

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,43 @@
33
## The absolute value of a number is the number without its sign.
44

55

6-
struct complext:
7-
var real: Int
8-
var imag: Int
6+
struct complex:
7+
var real_part: Int
8+
var imaginary_part: Int
99

1010

11-
fn __init__(inout self: Self, real: Int, imag: Int):
12-
self.real = real
13-
self.imag = imag
11+
fn __init__(inout self: Self, real_part: Int, imaginary_part: Int):
12+
self.real_part = real_part
13+
self.imaginary_part = imaginary_part
1414

1515
struct Math:
1616
@staticmethod
17-
fn abs(n: Int) -> Int:
17+
fn absolute(number: Int) -> Int:
1818
## Returns the absolute value of an integer.
19-
## >>> Math.abs(-5)
19+
## >>> Math.absolute(-5)
2020
## 5
21-
## >>> Math.abs(5)
21+
## >>> Math.absolute(5)
2222
## 5
23-
return n if n >= 0 else -n
23+
return number if number >= 0 else -number
2424

2525
@staticmethod
26-
fn abs(n: FloatLiteral) -> Int:
26+
fn absolute(number: FloatLiteral) -> FloatLiteral:
2727
## Returns the absolute value of a float.
28-
## >>> Math.abs(-5.5)
28+
## >>> Math.absolute(-5.5)
2929
## 5.5
30-
## >>> Math.abs(5.5)
30+
## >>> Math.absolute(5.5)
3131
## 5.5
32-
return n if n >= 0 else -n
32+
return number if number >= 0 else -number
3333

3434

3535
## For a complex number z = x + yi,
3636
## we define the absolute value |z| as being the distance from z to 0 in the complex plane C.
3737
## Reference: https://www2.clarku.edu/faculty/djoyce/complex/abs.html#:~:text=For%20a%20complex%20number%20z,on%20the%20real%20number%20line.
3838
@staticmethod
39-
fn abs(n: complext) -> FloatLiteral:
39+
fn absolute(number: complex) -> FloatLiteral:
4040
## Returns the absolute value of a complex number.
41-
## >>> Math.abs(complext(5, 0))
41+
## >>> Math.absolute(complex(5, 12))
42+
## 13.0
43+
## >>> Math.absolute(complex(3, 4))
4244
## 5.0
43-
## >>> Math.abs(complext(3, 4))
44-
## 5.0
45-
return math.sqrt(n.real ** 2 + n.imag ** 2)
45+
return math.sqrt(number.real_part ** 2 + number.imaginary_part ** 2)

0 commit comments

Comments
 (0)
0