@@ -47,11 +47,24 @@ pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self> {
4747 /// ```
4848 fn rem_euclid ( & self , v : & Self ) -> Self ;
4949
50- /// Returns both the euclidian division quotien and remainer
50+ /// Returns both the quotient and remainder from Euclidean division.
5151 ///
52- /// By default, it internaly calls both `Euclid::div_euclid` and `Euclid::rem_euclid`,
53- /// but it can be overwritten in order to implement some optimization.
54- fn div_with_rem_euclid ( & self , v : & Self ) -> ( Self , Self ) {
52+ /// By default, it internally calls both `Euclid::div_euclid` and `Euclid::rem_euclid`,
53+ /// but it can be overidden in order to implement some optimization.
54+ ///
55+ /// # Examples
56+ ///
57+ /// ```
58+ /// # use num_traits::Euclid;
59+ /// let x = 5u8;
60+ /// let y = 3u8;
61+ ///
62+ /// let div = Euclid::div_euclid(&x, &y);
63+ /// let rem = Euclid::rem_euclid(&x, &y);
64+ ///
65+ /// assert_eq!((div, rem), Euclid::div_rem_euclid(&x, &y));
66+ /// ```
67+ fn div_rem_euclid ( & self , v : & Self ) -> ( Self , Self ) {
5568 ( self . div_euclid ( v) , self . rem_euclid ( v) )
5669 }
5770}
@@ -183,11 +196,23 @@ pub trait CheckedEuclid: Euclid {
183196 /// division by zero. If any of that happens, `None` is returned.
184197 fn checked_rem_euclid ( & self , v : & Self ) -> Option < Self > ;
185198
186- /// Returns both the checked euclidian division quotien and remainer
199+ /// Returns both the quotient and remainder from checked Euclidean division.
187200 ///
188- /// By default, it internaly calls both `Euclid::div_euclid` and `Euclid::rem_euclid`,
189- /// but it can be overwritten in order to implement some optimization.
190- fn checked_div_with_rem_euclid ( & self , v : & Self ) -> Option < ( Self , Self ) > {
201+ /// By default, it internally calls both `CheckedEuclid::checked_div_euclid` and `CheckedEuclid::checked_rem_euclid`,
202+ /// but it can be overridden in order to implement some optimization.
203+ /// # Examples
204+ ///
205+ /// ```
206+ /// # use num_traits::CheckedEuclid;
207+ /// let x = 5u8;
208+ /// let y = 3u8;
209+ ///
210+ /// let div = CheckedEuclid::checked_div_euclid(&x, &y);
211+ /// let rem = CheckedEuclid::checked_rem_euclid(&x, &y);
212+ ///
213+ /// assert_eq!(Some((div.unwrap(), rem.unwrap())), CheckedEuclid::checked_div_rem_euclid(&x, &y));
214+ /// ```
215+ fn checked_div_rem_euclid ( & self , v : & Self ) -> Option < ( Self , Self ) > {
191216 Some ( ( self . checked_div_euclid ( v) ?, self . checked_rem_euclid ( v) ?) )
192217 }
193218}
@@ -278,8 +303,11 @@ mod tests {
278303 {
279304 let x: $t = 10 ;
280305 let y: $t = 3 ;
281- assert_eq!( Euclid :: div_euclid( & x, & y) , 3 ) ;
282- assert_eq!( Euclid :: rem_euclid( & x, & y) , 1 ) ;
306+ let div = Euclid :: div_euclid( & x, & y) ;
307+ let rem = Euclid :: rem_euclid( & x, & y) ;
308+ assert_eq!( div, 3 ) ;
309+ assert_eq!( rem, 1 ) ;
310+ assert_eq!( ( div, rem) , Euclid :: div_rem_euclid( & x, & y) ) ;
283311 }
284312 ) +
285313 } ;
@@ -300,6 +328,7 @@ mod tests {
300328 assert_eq!( Euclid :: div_euclid( & -x, & y) , 4 ) ;
301329 assert_eq!( Euclid :: rem_euclid( & x, & y) , 1 ) ;
302330 assert_eq!( Euclid :: rem_euclid( & -x, & y) , 2 ) ;
331+ assert_eq!( ( Euclid :: div_euclid( & x, & y) , Euclid :: rem_euclid( & x, & y) ) , Euclid :: div_rem_euclid( & x, & y) ) ;
303332 let x: $t = $t:: min_value( ) + 1 ;
304333 let y: $t = -1 ;
305334 assert_eq!( Euclid :: div_euclid( & x, & y) , $t:: max_value( ) ) ;
@@ -327,6 +356,7 @@ mod tests {
327356 <= 46.4 * <$t as crate :: float:: FloatCore >:: epsilon( ) ) ;
328357 assert!( Euclid :: div_euclid( & -x, & -y) * -y + Euclid :: rem_euclid( & -x, & -y) + x
329358 <= 46.4 * <$t as crate :: float:: FloatCore >:: epsilon( ) ) ;
359+ assert_eq!( ( Euclid :: div_euclid( & x, & y) , Euclid :: rem_euclid( & x, & y) ) , Euclid :: div_rem_euclid( & x, & y) ) ;
330360 }
331361 ) +
332362 } ;
@@ -343,8 +373,6 @@ mod tests {
343373 {
344374 assert_eq!( CheckedEuclid :: checked_div_euclid( & $t:: min_value( ) , & -1 ) , None ) ;
345375 assert_eq!( CheckedEuclid :: checked_rem_euclid( & $t:: min_value( ) , & -1 ) , None ) ;
346- assert_eq!( CheckedEuclid :: checked_div_euclid( & 1 , & 0 ) , None ) ;
347- assert_eq!( CheckedEuclid :: checked_rem_euclid( & 1 , & 0 ) , None ) ;
348376 }
349377 ) +
350378 } ;
0 commit comments