Skip to content
This repository
Browse code

introduce X::Numeric::Real

Signed-off-by: Moritz Lenz <moritz@faui2k3.org>
  • Loading branch information...
commit 7fb26aef67f2552df5647acb7db9f746ede7605b 1 parent ce9cbc7
felher authored June 12, 2012 moritz committed July 12, 2012
14  S32-setting-library/Exception.pod
Source Rendered
@@ -1235,6 +1235,20 @@ not know how to handle.
1235 1235
         }
1236 1236
     }
1237 1237
 
  1238
+=head2 X::Numeric::Real
  1239
+
  1240
+Occurs when an attempt to coerce a C<Numeric> to a C<Real>, C<Num>, C<Int> or
  1241
+C<Rat> fails (due to a number with a nonzero imaginary part, for instance).
  1242
+
  1243
+    my class X::Numeric::Real is Exception {
  1244
+        has $.target;
  1245
+        has $.reason;
  1246
+
  1247
+        method message() {
  1248
+            "Can not convert Numeric to {$.target.^name}: $.reason";
  1249
+        }
  1250
+    }
  1251
+
1238 1252
 =head1 Related types
1239 1253
 
1240 1254
 =head2 Failure
10  S32-setting-library/Numeric.pod
Source Rendered
@@ -85,28 +85,30 @@ mathematical functions.
85 85
 
86 86
 If this C<Numeric> is equivalent to a C<Real>, return that C<Real>.  
87 87
 (For instance, if this number is a C<Complex> with a zero imaginary part.)  
88  
-Fail otherwise.
  88
+Fail with C<X::Numeric::Real> otherwise.
89 89
 
90 90
 =item Int
91 91
 
92 92
  multi method Int ( --> Int )
93 93
 
94 94
 If this C<Numeric> is equivalent to a C<Real>, return the equivalent of
95  
-calling C<truncate> on that C<Real> to get an C<Int>. 
  95
+calling C<truncate> on that C<Real> to get an C<Int>. Fail with
  96
+C<X::Numeric::Real> otherwise.
96 97
 
97 98
 =item Rat
98 99
 
99 100
  multi method Rat ( Real $epsilon = 1.0e-6 --> Rat )
100 101
 
101 102
 If this C<Numeric> is equivalent to a C<Real>, return a C<Rat> which is
102  
-within C<$epsilon> of that C<Real>'s value.
  103
+within C<$epsilon> of that C<Real>'s value. Fail with C<X::Numeric::Real>
  104
+otherwise.
103 105
 
104 106
 =item Num
105 107
 
106 108
  multi method Num ( --> Num )
107 109
 
108 110
 If this C<Numeric> is equivalent to a C<Real>, return that C<Real> as a C<Num>
109  
-as accurately as is possible.
  111
+as accurately as is possible. Fail with C<X::Numeric::Real> otherwise.
110 112
 
111 113
 =item succ
112 114
 

0 notes on commit 7fb26ae

Please sign in to comment.
Something went wrong with that request. Please try again.