about summary refs log tree commit diff
path: root/example/std_example.rs
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-07-17 20:45:54 +0200
committerbjorn3 <bjorn3@users.noreply.github.com>2019-07-26 11:29:35 +0200
commit834a3bf49c9e6cc422a0028926654d46dc5749ba (patch)
treec9c01802d013c7a734dbe03af24bde3b62927fdd /example/std_example.rs
parent641a210ff688d8101688b32650d09c270d381b02 (diff)
downloadrust-834a3bf49c9e6cc422a0028926654d46dc5749ba.tar.gz
rust-834a3bf49c9e6cc422a0028926654d46dc5749ba.zip
[WIP]
Diffstat (limited to 'example/std_example.rs')
-rw-r--r--example/std_example.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/example/std_example.rs b/example/std_example.rs
index c0ec0bb5b73..a67ca2f79c7 100644
--- a/example/std_example.rs
+++ b/example/std_example.rs
@@ -1,7 +1,25 @@
 #![feature(core_intrinsics)]
 
 use std::io::Write;
+use std::intrinsics;
+
+fn checked_div_i128(lhs: i128, rhs: i128) -> Option<i128> {
+    if rhs == 0 || (lhs == -170141183460469231731687303715884105728 && rhs == -1) {
+        None
+    } else {
+        Some(unsafe { intrinsics::unchecked_div(lhs, rhs) })
+    }
+}
+
+fn checked_div_u128(lhs: u128, rhs: u128) -> Option<u128> {
+    match rhs {
+        0 => None,
+        rhs => Some(unsafe { intrinsics::unchecked_div(lhs, rhs) })
+    }
+}
 
 fn main() {
+    checked_div_i128(0i128, 2i128);
+    checked_div_u128(0u128, 2u128);
     assert_eq!(1u128 + 2, 3);
 }