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.
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.
11 //! Operations and constants for unsigned 32-bits integers (`u32` type)
13 #![allow(non_uppercase_statics)]
18 use from_str::FromStr;
19 use num::{Bitwise, Bounded};
20 use num::{CheckedAdd, CheckedSub, CheckedMul};
21 use num::{CheckedDiv, Zero, One, strconv};
22 use num::{ToStrRadix, FromStrRadix};
23 use option::{Option, Some, None};
27 uint_module!(u32, i32, 32)
29 impl CheckedAdd for u32 {
31 fn checked_add(&self, v: &u32) -> Option<u32> {
33 let (x, y) = intrinsics::u32_add_with_overflow(*self, *v);
34 if y { None } else { Some(x) }
39 impl CheckedSub for u32 {
41 fn checked_sub(&self, v: &u32) -> Option<u32> {
43 let (x, y) = intrinsics::u32_sub_with_overflow(*self, *v);
44 if y { None } else { Some(x) }
49 impl CheckedMul for u32 {
51 fn checked_mul(&self, v: &u32) -> Option<u32> {
53 let (x, y) = intrinsics::u32_mul_with_overflow(*self, *v);
54 if y { None } else { Some(x) }