mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 07:41:12 +00:00
20 lines
No EOL
359 B
Rust
20 lines
No EOL
359 B
Rust
/// An i64 that always panics on overflow.
|
|
pub struct Int(i64);
|
|
|
|
impl Int {
|
|
pub fn abs(&self) -> Self {
|
|
let Int(int_self) = self;
|
|
|
|
let (output, underflowed) = int_self.overflowing_abs();
|
|
|
|
if underflowed {
|
|
underflow_panic();
|
|
}
|
|
|
|
Int(output)
|
|
}
|
|
}
|
|
|
|
fn underflow_panic() -> ! {
|
|
panic!("Underflow!");
|
|
} |