about summary refs log tree commit diff
path: root/example
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-07-24 13:16:36 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2019-07-26 11:30:39 +0200
commit63b82238bbe54643c63a8693299d6a9f4c0b0358 (patch)
tree06d7c44095f40107fe0aaa321f096a86fb5731d7 /example
parent4d35be684da8c82ac699093132bda4a5292f9578 (diff)
downloadrust-63b82238bbe54643c63a8693299d6a9f4c0b0358.tar.gz
rust-63b82238bbe54643c63a8693299d6a9f4c0b0358.zip
Implement 128bit checked add and sub
Diffstat (limited to 'example')
-rw-r--r--example/mini_core.rs27
-rw-r--r--example/std_example.rs3
2 files changed, 3 insertions, 27 deletions
diff --git a/example/mini_core.rs b/example/mini_core.rs
index fa47831b648..221cdb3e863 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -44,12 +44,10 @@ unsafe impl Copy for u8 {}
 unsafe impl Copy for u16 {}
 unsafe impl Copy for u32 {}
 unsafe impl Copy for u64 {}
-unsafe impl Copy for u128 {}
 unsafe impl Copy for usize {}
 unsafe impl Copy for i8 {}
 unsafe impl Copy for i16 {}
 unsafe impl Copy for i32 {}
-unsafe impl Copy for i128 {}
 unsafe impl Copy for isize {}
 unsafe impl Copy for char {}
 unsafe impl<'a, T: ?Sized> Copy for &'a T {}
@@ -146,22 +144,6 @@ impl Add for usize {
     }
 }
 
-impl Add for u128 {
-    type Output = Self;
-
-    fn add(self, rhs: Self) -> Self {
-        self + rhs
-    }
-}
-
-impl Add for i128 {
-    type Output = Self;
-
-    fn add(self, rhs: Self) -> Self {
-        self + rhs
-    }
-}
-
 #[lang = "sub"]
 pub trait Sub<RHS = Self> {
     type Output;
@@ -286,15 +268,6 @@ impl PartialEq for i32 {
     }
 }
 
-impl PartialEq for i128 {
-    fn eq(&self, other: &i128) -> bool {
-        (*self) == (*other)
-    }
-    fn ne(&self, other: &i128) -> bool {
-        (*self) != (*other)
-    }
-}
-
 impl PartialEq for isize {
     fn eq(&self, other: &isize) -> bool {
         (*self) == (*other)
diff --git a/example/std_example.rs b/example/std_example.rs
index 9e9a7a67e05..f9fc1f2cde3 100644
--- a/example/std_example.rs
+++ b/example/std_example.rs
@@ -23,6 +23,9 @@ fn main() {
     checked_div_u128(0u128, 2u128);
     assert_eq!(1u128 + 2, 3);
 
+    // overflow panic
+    // 0xFEDCBA987654321123456789ABCDEFu128 + 0xFEDCBA987654321123456789ABCDEFu128;
+
     println!("{}", 0b100010000000000000000000000000000u128 >> 10);
     println!("{}", 0xFEDCBA987654321123456789ABCDEFu128 >> 64);
     println!("{} >> 64 == {}", 0xFEDCBA987654321123456789ABCDEFu128 as i128, 0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64);