]> git.lizzy.rs Git - rust.git/blob - src/libstd/num/u64.rs
Convert most code to new inner attribute syntax.
[rust.git] / src / libstd / num / u64.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Operations and constants for unsigned 64-bits integer (`u64` type)
12
13 #![allow(non_uppercase_statics)]
14
15 use prelude::*;
16
17 use default::Default;
18 use from_str::FromStr;
19 use num::{Bitwise, Bounded};
20 #[cfg(target_word_size = "64")]
21 use num::CheckedMul;
22 use num::{CheckedAdd, CheckedSub};
23 use num::{CheckedDiv, Zero, One, strconv};
24 use num::{ToStrRadix, FromStrRadix};
25 use option::{Option, Some, None};
26 use str;
27 use intrinsics;
28
29 uint_module!(u64, i64, 64)
30
31 impl CheckedAdd for u64 {
32     #[inline]
33     fn checked_add(&self, v: &u64) -> Option<u64> {
34         unsafe {
35             let (x, y) = intrinsics::u64_add_with_overflow(*self, *v);
36             if y { None } else { Some(x) }
37         }
38     }
39 }
40
41 impl CheckedSub for u64 {
42     #[inline]
43     fn checked_sub(&self, v: &u64) -> Option<u64> {
44         unsafe {
45             let (x, y) = intrinsics::u64_sub_with_overflow(*self, *v);
46             if y { None } else { Some(x) }
47         }
48     }
49 }
50
51 impl CheckedMul for u64 {
52     #[inline]
53     fn checked_mul(&self, v: &u64) -> Option<u64> {
54         unsafe {
55             let (x, y) = intrinsics::u64_mul_with_overflow(*self, *v);
56             if y { None } else { Some(x) }
57         }
58     }
59 }