pub trait RoundToMultipleOfPowerOf2Assign<RHS> {
    fn round_to_multiple_of_power_of_2_assign(
        &mut self,
        pow: RHS,
        rm: RoundingMode
    ); }
Expand description

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

Required Methods

Implementations on Foreign Types

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Rounds a number to a multiple of $2^k$ in place, according to a specified rounding mode.

The only rounding mode that is guaranteed to return without a panic is Down.

See the RoundToMultipleOfPowerOf2 documentation for details.

The following two expressions are equivalent:

  • x.round_to_multiple_of_power_of_2_assign(pow, RoundingMode::Exact);
  • assert!(x.divisible_by_power_of_2(pow));

but the latter should be used as it is clearer and more efficient.

Worst-case complexity

Constant time and additional memory.

Panics
  • If rm is Exact, but self is not a multiple of the power of 2.
  • If rm is Floor, but self is negative with a too-large absolute value to round to the next lowest multiple.
  • If rm is Ceiling, but self is too large to round to the next highest multiple.
  • If rm is Up, but self has too large an absolute value to round to the next multiple with a greater absolute value.
  • If rm is Nearest, but the nearest multiple is outside the representable range.
Examples

See here.

Implementors