MapRange
MapRange maps a value from one range to a second range.
For integer-integer mapping it doesn't escalate to floats, but uses the next bigger integer type.
It works better than integer divide + scale up, as it truly fills the full target range. Especially an end-point in the source range maps to an end-point in the target range.
This is implemented for all combinations of source/target type except i128 and u128.
use MapRange;
//
// in range
//
let r2 = 17u8.map_range.expect;
assert_eq!;
let r2 = 10u8.map_range.expect;
assert_eq!;
let r2 = 20u8.map_range.expect;
assert_eq!;
//
// out of range
//
let r2: = 5u8.map_range;
assert_eq!;
//
// reversed bounds
//
let r2: = 17u8.map_range;
assert_eq!;
let r2: = 17u8.map_range;
assert_eq!;
//
// boundaries
//
let r2 = 17u8
.map_range
.expect;
assert_eq!;
let r2 = 10u8.map_range.expect;
assert_eq!;
//
// signed
//
let r2 = .map_range.expect;
assert_eq!;
let r2 = 90u8.map_range.expect;
assert_eq!;
//
// float
//
let r2 = 0.31f64.map_range.expect;
assert_eq!;
let r2 = 81u8.map_range.expect;
assert_eq!;