Merge #79
79: Updated documentation to note the pow(0, 0) case. r=cuviper a=meltinglava Ref #78 Co-authored-by: Roald <meltinglava>
This commit is contained in:
commit
5985a8b750
|
@ -173,6 +173,8 @@ mod float_impls {
|
||||||
|
|
||||||
/// Raises a value to the power of exp, using exponentiation by squaring.
|
/// Raises a value to the power of exp, using exponentiation by squaring.
|
||||||
///
|
///
|
||||||
|
/// Note that `0⁰` (`pow(0, 0)`) returnes `1`. Mathematically this is undefined.
|
||||||
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
|
@ -180,6 +182,7 @@ mod float_impls {
|
||||||
///
|
///
|
||||||
/// assert_eq!(pow(2i8, 4), 16);
|
/// assert_eq!(pow(2i8, 4), 16);
|
||||||
/// assert_eq!(pow(6u8, 3), 216);
|
/// assert_eq!(pow(6u8, 3), 216);
|
||||||
|
/// assert_eq!(pow(0u8, 0), 1); // Be aware if this case affects you
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn pow<T: Clone + One + Mul<T, Output = T>>(mut base: T, mut exp: usize) -> T {
|
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.
|
/// Raises a value to the power of exp, returning `None` if an overflow occurred.
|
||||||
///
|
///
|
||||||
|
/// Note that `0⁰` (`checked_pow(0, 0)`) returnes `Some(1)`. Mathematically this is undefined.
|
||||||
|
///
|
||||||
/// Otherwise same as the `pow` function.
|
/// Otherwise same as the `pow` function.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # 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(2i8, 4), Some(16));
|
||||||
/// assert_eq!(checked_pow(7i8, 8), None);
|
/// assert_eq!(checked_pow(7i8, 8), None);
|
||||||
/// assert_eq!(checked_pow(7u32, 8), Some(5_764_801));
|
/// 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]
|
#[inline]
|
||||||
pub fn checked_pow<T: Clone + One + CheckedMul>(mut base: T, mut exp: usize) -> Option<T> {
|
pub fn checked_pow<T: Clone + One + CheckedMul>(mut base: T, mut exp: usize) -> Option<T> {
|
||||||
|
|
Loading…
Reference in New Issue