sum_range 0.1.0

The sum of all consecutive numbers, both even and odd.
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented4 out of 5 items with examples
  • Size
  • Source code size: 24.89 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.31 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 19s Average build duration of successful builds.
  • all releases: 19s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • pic16f877ccs/sum_range
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • pic16f877ccs

Sum_Range

This crate provides a trait for efficiently calculating the sum of numbers within a range, including support for odd and even number sums.

Supported Range Types

  • Range
  • RangeInclusive
  • RangeTo
  • RangeToInclusive

Trait Methods

  • sum_range: Calculates the sum of all numbers in the range.
  • sum_odd_range: Calculates the sum of all odd numbers in the range.
  • sum_even_range: Calculates the sum of all even numbers in the range.

Note

  • For RangeTo and RangeToInclusive, signed integer types are not supported.

Usage

use sum_range::SumRange;

assert_eq!((1..11).sum_range(), 55u8);
assert_eq!((0..=12).sum_range(), 78u8);
assert_eq!((-10..12).sum_odd_range(), 11i16);
assert_eq!((-5..=5).sum_even_range(), 0i32);

License

This crate is licensed under the MIT license.