Skip to content

Commit

Permalink
Add documentation for complex methods inside Number (#14538)
Browse files Browse the repository at this point in the history
  • Loading branch information
meatball133 committed May 13, 2024
1 parent 262e3af commit 085d50c
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/complex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,12 @@ struct Complex
end

struct Number
# Returns a `Complex` object with the value of `self` as the real part.
def to_c : Complex
Complex.new(self, 0)
end

# Returns a `Complex` object with the value of `self` as the imaginary part.
def i : Complex
Complex.new(0, self)
end
Expand All @@ -310,6 +312,9 @@ struct Number
other == self
end

# [Cis](https://en.wikipedia.org/wiki/Cis_(mathematics)) is a mathematical notation representing `cos x + i sin x`.
#
# Returns a `Complex` object with real part `Math.cos(self)` and imaginary part `Math.sin(self)`, where `self` represents the angle in radians.
def cis : Complex
Complex.new(Math.cos(self), Math.sin(self))
end
Expand Down

0 comments on commit 085d50c

Please sign in to comment.