@@ -69,7 +69,12 @@ pub type BigRational = Ratio<BigInt>;
69
69
70
70
/// These method are `const` for Rust 1.31 and later.
71
71
impl < T > Ratio < T > {
72
- /// Creates a `Ratio` without checking for `denom == 0` or reducing.
72
+ /**
73
+ Creates a `Ratio` without checking for `denom == 0` or reducing.
74
+
75
+ **There are several methods that will panic if used on a `Ratio` with
76
+ `denom == 0`.**
77
+ */
73
78
#[ inline]
74
79
pub const fn new_raw ( numer : T , denom : T ) -> Ratio < T > {
75
80
Ratio { numer, denom }
@@ -89,7 +94,11 @@ impl<T> Ratio<T> {
89
94
}
90
95
91
96
impl < T : Clone + Integer > Ratio < T > {
92
- /// Creates a new `Ratio`. Fails if `denom` is zero.
97
+ /**
98
+ Creates a new `Ratio`.
99
+
100
+ **Panics if `denom` is zero.**
101
+ */
93
102
#[ inline]
94
103
pub fn new ( numer : T , denom : T ) -> Ratio < T > {
95
104
let mut ret = Ratio :: new_raw ( numer, denom) ;
@@ -115,7 +124,11 @@ impl<T: Clone + Integer> Ratio<T> {
115
124
self . denom . is_one ( )
116
125
}
117
126
118
- /// Puts self into lowest terms, with denom > 0.
127
+ /**
128
+ Puts self into lowest terms, with `denom` > 0.
129
+
130
+ **Panics if `denom` is zero.**
131
+ */
119
132
fn reduce ( & mut self ) {
120
133
if self . denom . is_zero ( ) {
121
134
panic ! ( "denominator == 0" ) ;
@@ -146,19 +159,25 @@ impl<T: Clone + Integer> Ratio<T> {
146
159
}
147
160
}
148
161
149
- /// Returns a reduced copy of self.
150
- ///
151
- /// In general, it is not necessary to use this method, as the only
152
- /// method of procuring a non-reduced fraction is through `new_raw`.
162
+ /**
163
+ Returns a reduced copy of self.
164
+
165
+ In general, it is not necessary to use this method, as the only
166
+ method of procuring a non-reduced fraction is through `new_raw`.
167
+
168
+ **Panics if `denom` is zero.**
169
+ */
153
170
pub fn reduced ( & self ) -> Ratio < T > {
154
171
let mut ret = self . clone ( ) ;
155
172
ret. reduce ( ) ;
156
173
ret
157
174
}
158
175
159
- /// Returns the reciprocal.
160
- ///
161
- /// Fails if the `Ratio` is zero.
176
+ /**
177
+ Returns the reciprocal.
178
+
179
+ **Panics if the `Ratio` is zero.**
180
+ */
162
181
#[ inline]
163
182
pub fn recip ( & self ) -> Ratio < T > {
164
183
self . clone ( ) . into_recip ( )
0 commit comments