ptal / intervallum

Integer interval arithmetic library
Apache License 2.0
17 stars 7 forks source link

Whole is off-by-one #21

Closed fabianfreyer closed 1 year ago

fabianfreyer commented 1 year ago

For example:

let whole_u8: Interval<u8> = Interval::whole();
assert_eq!(whole_u8.lower(), u8::MIN); // Ok
assert_eq!(whole_u8.upper(), u8::MAX); // Fails, whole_u8.upper() is 0xfe, not 0xff.
ptal commented 1 year ago

Well, actually it was a design decision, so the width of the interval can be represented by an unsigned integer of the same kind as the bounds, e.g., the number of elements in the interval whole_u8 is 256, which is cannot be represented in a u8. The functions to get the min and max are u8::min_value() and u8::max_value(), implemented by the trait Width in the file ops.rs.