File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1111//! "Wikipedia contributors. Integer square root. Wikipedia, The Free
1212//! Encyclopedia."
1313
14+ use crate :: assert_unsafe_precondition;
15+
1416/// This array stores the [integer square roots][1] and remainders of each
1517/// [`u8`](prim@u8) value. For example, `U8_ISQRT_WITH_REMAINDER[17]` will be
1618/// `(4, 1)` because the integer square root of 17 is 4 and because 17 is 1
@@ -96,6 +98,16 @@ macro_rules! signed_fn {
9698 without modifying the original"]
9799 #[ inline( always) ]
98100 pub const unsafe fn $SignedT( n: $SignedT) -> $SignedT {
101+ assert_unsafe_precondition!(
102+ check_library_ub,
103+ concat!(
104+ "`isqrt` internal error: Passing a negative number to `core::num::int_sqrt::" ,
105+ stringify!( $SignedT) ,
106+ "` causes undefined behavior."
107+ ) ,
108+ ( n: $SignedT = n) => n >= 0
109+ ) ;
110+
99111 $UnsignedT( n as $UnsignedT) as $SignedT
100112 }
101113 } ;
You can’t perform that action at this time.
0 commit comments