Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Last active May 25, 2016 16:55
Show Gist options
  • Save dogbert17/50d2cdaf45861a40291b2ec5240f1626 to your computer and use it in GitHub Desktop.
Save dogbert17/50d2cdaf45861a40291b2ec5240f1626 to your computer and use it in GitHub Desktop.
Attempt to document methods floor/ceiling/round and truncate in Complex.pod
=head2 method floor
Defined as:
method floor(Complex:D:) returns Complex:D
Usage:
COMPLEX.floor
Returns C<self.re.floor + self.im.floor>. That is, each of the real and
imaginary parts is rounded to the highest integer not greater than
the value of that part.
say (1.2-3.8i).floor; # 1-4i
=head2 method ceiling
Defined as:
method ceiling(Complex:D:) returns Complex:D
Usage:
COMPLEX.ceiling
Returns C<self.re.ceiling + self.im.ceiling>. That is, each of the real and
imaginary parts is rounded to the lowest integer not less than the value
of that part.
say (1.2-3.8i).ceiling; # 2-3i
=head2 method round
Defined as:
multi method round(Complex:D:) returns Complex:D
multi method round(Complex:D: Real() $scale) returns Complex:D
Usage:
COMPLEX.round
COMPLEX.reound($scale)
With no arguments, rounds both the real and imaginary parts to the nearest
integer and returns a new C<Complex> number. If C<$scale> is given, rounds both
parts of the invocant to the nearest multiple of C<$scale>. Uses the same
algorithm as L<Real.round|/type/Real#method_round> on each part of the number.
say (1.2-3.8i).round; # 1-4i
say (1.256-3.875i).round(0.1); # 1.3-3.9i
=head2 method truncate
Defined as:
method truncate(Complex:D:) returns Complex:D
Usage:
COMPLEX.truncate
Removes the fractional part of both the real and imaginary parts of the
number, using L<Real.truncate|/type/Real#method_truncate>, and returns the result as a new C<Complex>.
say (1.2-3.8i).truncate; # 1-3i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment