2016-08-11 22:25:13 -07:00
|
|
|
pub enum Cmp {
|
|
|
|
Equal,
|
|
|
|
Greater,
|
|
|
|
Less,
|
|
|
|
}
|
|
|
|
|
2016-07-24 18:35:50 -07:00
|
|
|
pub fn min(inline T: type, x: T, y: T) -> T {
|
2016-02-02 01:43:33 -08:00
|
|
|
if (x < y) x else y
|
|
|
|
}
|
|
|
|
|
2016-07-24 18:35:50 -07:00
|
|
|
pub fn max(inline T: type, x: T, y: T) -> T {
|
2016-05-08 16:05:41 -07:00
|
|
|
if (x > y) x else y
|
|
|
|
}
|
2016-07-24 18:35:50 -07:00
|
|
|
|
|
|
|
pub error Overflow;
|
2016-08-16 22:42:50 -07:00
|
|
|
pub fn mulOverflow(inline T: type, a: T, b: T) -> %T {
|
2016-07-24 18:35:50 -07:00
|
|
|
var answer: T = undefined;
|
2016-08-16 22:42:50 -07:00
|
|
|
if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
2016-07-24 18:35:50 -07:00
|
|
|
}
|
2016-08-16 22:42:50 -07:00
|
|
|
pub fn addOverflow(inline T: type, a: T, b: T) -> %T {
|
2016-07-24 18:35:50 -07:00
|
|
|
var answer: T = undefined;
|
2016-08-16 22:42:50 -07:00
|
|
|
if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
2016-07-24 18:35:50 -07:00
|
|
|
}
|
2016-08-16 22:42:50 -07:00
|
|
|
pub fn subOverflow(inline T: type, a: T, b: T) -> %T {
|
2016-07-24 18:35:50 -07:00
|
|
|
var answer: T = undefined;
|
2016-08-16 22:42:50 -07:00
|
|
|
if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer
|
2016-07-24 18:35:50 -07:00
|
|
|
}
|