| Crates.io | sum_range |
| lib.rs | sum_range |
| version | 0.1.0 |
| created_at | 2024-11-30 21:13:37.698651+00 |
| updated_at | 2024-11-30 21:13:37.698651+00 |
| description | The sum of all consecutive numbers, both even and odd. |
| homepage | https://github.com/pic16f877ccs/sum_range |
| repository | https://github.com/pic16f877ccs/sum_range |
| max_upload_size | |
| id | 1466987 |
| size | 22,406 |
This crate provides a trait for efficiently calculating the sum of numbers within a range, including support for odd and even number sums.
RangeRangeInclusiveRangeToRangeToInclusivesum_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.RangeTo and RangeToInclusive, signed integer types are not supported.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);
This crate is licensed under the MIT license.