Skip to content

Commit

Permalink
introduce X::Numeric::Real
Browse files Browse the repository at this point in the history
Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information
felher authored and moritz committed Jul 12, 2012
1 parent ce9cbc7 commit 7fb26ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions S32-setting-library/Exception.pod
Expand Up @@ -1235,6 +1235,20 @@ not know how to handle.
}
}

=head2 X::Numeric::Real

Occurs when an attempt to coerce a C<Numeric> to a C<Real>, C<Num>, C<Int> or
C<Rat> fails (due to a number with a nonzero imaginary part, for instance).

my class X::Numeric::Real is Exception {
has $.target;
has $.reason;

method message() {
"Can not convert Numeric to {$.target.^name}: $.reason";
}
}

=head1 Related types

=head2 Failure
Expand Down
10 changes: 6 additions & 4 deletions S32-setting-library/Numeric.pod
Expand Up @@ -85,28 +85,30 @@ mathematical functions.

If this C<Numeric> is equivalent to a C<Real>, return that C<Real>.
(For instance, if this number is a C<Complex> with a zero imaginary part.)
Fail otherwise.
Fail with C<X::Numeric::Real> otherwise.

=item Int

multi method Int ( --> Int )

If this C<Numeric> is equivalent to a C<Real>, return the equivalent of
calling C<truncate> on that C<Real> to get an C<Int>.
calling C<truncate> on that C<Real> to get an C<Int>. Fail with
C<X::Numeric::Real> otherwise.

=item Rat

multi method Rat ( Real $epsilon = 1.0e-6 --> Rat )

If this C<Numeric> is equivalent to a C<Real>, return a C<Rat> which is
within C<$epsilon> of that C<Real>'s value.
within C<$epsilon> of that C<Real>'s value. Fail with C<X::Numeric::Real>
otherwise.

=item Num

multi method Num ( --> Num )

If this C<Numeric> is equivalent to a C<Real>, return that C<Real> as a C<Num>
as accurately as is possible.
as accurately as is possible. Fail with C<X::Numeric::Real> otherwise.

=item succ

Expand Down

0 comments on commit 7fb26ae

Please sign in to comment.