Browse Source

Updated documentation to note the pow(0, 0) case.

Roald 6 years ago
parent
commit
0f228be4d5
1 changed files with 6 additions and 0 deletions
  1. 6 0
      src/pow.rs

+ 6 - 0
src/pow.rs

@@ -173,6 +173,8 @@ mod float_impls {
 
 /// Raises a value to the power of exp, using exponentiation by squaring.
 ///
+/// Note that `0⁰` (`pow(0, 0)`) returnes `1`. Mathematicly this is undefined.
+///
 /// # Example
 ///
 /// ```rust
@@ -180,6 +182,7 @@ mod float_impls {
 ///
 /// assert_eq!(pow(2i8, 4), 16);
 /// assert_eq!(pow(6u8, 3), 216);
+/// assert_eq!(pow(0u8, 0), 1); // Be aware if this case affects you
 /// ```
 #[inline]
 pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) -> T {
@@ -208,6 +211,8 @@ pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) ->
 
 /// Raises a value to the power of exp, returning `None` if an overflow occurred.
 ///
+/// Note that `0⁰` (`checked_pow(0, 0)`) returnes `Some(1)`. Mathematicly this is undefined.
+///
 /// Otherwise same as the `pow` function.
 ///
 /// # Example
@@ -218,6 +223,7 @@ pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) ->
 /// assert_eq!(checked_pow(2i8, 4), Some(16));
 /// assert_eq!(checked_pow(7i8, 8), None);
 /// assert_eq!(checked_pow(7u32, 8), Some(5_764_801));
+/// assert_eq!(checked_pow(0u32, 0), Some(1)); // Be aware if this case affect you
 /// ```
 #[inline]
 pub fn checked_pow<T: Clone + One + CheckedMul>(mut base: T, mut exp: usize) -> Option<T> {