Skip to content

Commit 8fd4d5c

Browse files
committed
Documented complex object, fix some errors in math documentation.
1 parent 0e5a007 commit 8fd4d5c

39 files changed

+290
-39
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
Returns the absolute value (magnitude) of the complex number.
3+
float complex::abs() const;
4+
*/
5+
6+
// Example:
7+
void main() {
8+
complex c(3, 4);
9+
alert("Magnitude =", c.abs());
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Adds two complex numbers and returns the result.
3+
complex complex::opAdd(const complex&in other) const;
4+
## Arguments:
5+
* const complex&in other: the complex number to add.
6+
## Returns:
7+
complex: a new complex object containing the value of the addition.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
complex c = a + b;
20+
alert("a + b =", to_string(c));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Adds another complex number to this one.
3+
complex& complex::opAddAssign(const complex&in other);
4+
## Arguments:
5+
* const complex&in other: the complex number to add.
6+
## Returns:
7+
complex&: a reference to the complex number being operated on.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
a += b;
20+
alert("a + b =", to_string(a));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Divides this complex number by another and returns the result.
3+
complex complex::opDiv(const complex&in other) const;
4+
## Arguments:
5+
* const complex&in other: the complex number to divide by.
6+
## Returns:
7+
complex: a new complex object containing the value of the division.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
complex c = a / b;
20+
alert("a / b =", to_string(c));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Divides this complex number by another.
3+
complex& complex::opDivAssign(const complex&in other);
4+
## Arguments:
5+
* const complex&in other: the complex number to divide by.
6+
## Returns:
7+
complex&: a reference to the complex number being operated on.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
a /= b;
20+
alert("a / b =", to_string(a));
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
Checks if two complex numbers are equal.
3+
bool complex::opEquals(const complex&in other) const;
4+
## Arguments:
5+
* const complex&in other: the complex number to compare to.
6+
## Returns:
7+
bool: true if the two complex numbers are equal, false otherwise.
8+
*/
9+
10+
// Example:
11+
void main() {
12+
complex a(1, 2);
13+
complex b(1, 2);
14+
alert("a equals b?", a == b);
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Multiplies two complex numbers and returns the result.
3+
complex complex::opMul(const complex&in other) const;
4+
## Arguments:
5+
* const complex&in other: the complex number to multiply with.
6+
## Returns:
7+
complex: a new complex object containing the value of the multiplication.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
complex c = a * b;
20+
alert("a * b =", to_string(c));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Multiplies this complex number by another.
3+
complex& complex::opMulAssign(const complex&in other);
4+
## Arguments:
5+
* const complex&in other: the complex number to multiply with.
6+
## Returns:
7+
complex&: a reference to the complex number being operated on.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(1, 2);
18+
complex b(3, 4);
19+
a *= b;
20+
alert("a * b =", to_string(a));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Subtracts a complex number from this one and returns the result.
3+
complex complex::opSub(const complex&in other) const;
4+
## Arguments:
5+
* const complex&in other: the complex number to subtract.
6+
## Returns:
7+
complex: a new complex object containing the value of the subtraction.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(5, 6);
18+
complex b(2, 3);
19+
complex c = a - b;
20+
alert("a - b =", to_string(c));
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
Subtracts another complex number from this one.
3+
complex& complex::opSubAssign(const complex&in other);
4+
## Arguments:
5+
* const complex&in other: the complex number to subtract.
6+
## Returns:
7+
complex&: a reference to the complex number being operated on.
8+
*/
9+
10+
// Example:
11+
// Helper function to print a complex number.
12+
string to_string(const complex&in c) {
13+
return "(" + c.r + ", " + c.i + ")";
14+
}
15+
16+
void main() {
17+
complex a(5, 6);
18+
complex b(2, 3);
19+
a -= b;
20+
alert("a - b =", to_string(a));
21+
}

0 commit comments

Comments
 (0)