Skip to content

Commit a495b5a

Browse files
author
Jan-Olof Hendig
committed
Added docs for methods floor, ceiling, round and truncate in class Complex
1 parent c4101f5 commit a495b5a

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

doc/Type/Complex.pod

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,71 @@ Usage:
101101
Returns a two-element list of the polar coordinates for this value,
102102
i.e. magnitude and angle in radians.
103103
104+
=head2 method floor
105+
106+
Defined as:
107+
108+
method floor(Complex:D:) returns Complex:D
109+
110+
Usage:
111+
112+
COMPLEX.floor
113+
114+
Returns C<self.re.floor + self.im.floor>. That is, each of the real and
115+
imaginary parts is rounded to the highest integer not greater than
116+
the value of that part.
117+
118+
say (1.2-3.8i).floor; # 1-4i
119+
120+
=head2 method ceiling
121+
122+
Defined as:
123+
124+
method ceiling(Complex:D:) returns Complex:D
125+
126+
Usage:
127+
128+
COMPLEX.ceiling
129+
130+
Returns C<self.re.ceiling + self.im.ceiling>. That is, each of the real and
131+
imaginary parts is rounded to the lowest integer not less than the value
132+
of that part.
133+
134+
say (1.2-3.8i).ceiling; # 2-3i
135+
136+
=head2 method round
137+
138+
Defined as:
139+
140+
multi method round(Complex:D:) returns Complex:D
141+
multi method round(Complex:D: Real() $scale) returns Complex:D
142+
143+
Usage:
144+
145+
COMPLEX.round
146+
COMPLEX.round($scale)
147+
148+
With no arguments, rounds both the real and imaginary parts to the nearest
149+
integer and returns a new C<Complex> number. If C<$scale> is given, rounds both
150+
parts of the invocant to the nearest multiple of C<$scale>. Uses the same
151+
algorithm as L<Real.round|/type/Real#method_round> on each part of the number.
152+
153+
say (1.2-3.8i).round; # 1-4i
154+
say (1.256-3.875i).round(0.1); # 1.3-3.9i
155+
156+
=head2 method truncate
157+
158+
Defined as:
159+
160+
method truncate(Complex:D:) returns Complex:D
161+
162+
Usage:
163+
164+
COMPLEX.truncate
165+
166+
Removes the fractional part of both the real and imaginary parts of the
167+
number, using L<Real.truncate|/type/Real#method_truncate>, and returns the result as a new C<Complex>.
168+
169+
say (1.2-3.8i).truncate; # 1-3i
170+
104171
=end pod

0 commit comments

Comments
 (0)