File tree 1 file changed +12
-0
lines changed
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 11
11
//! "Wikipedia contributors. Integer square root. Wikipedia, The Free
12
12
//! Encyclopedia."
13
13
14
+ use crate :: assert_unsafe_precondition;
15
+
14
16
/// This array stores the [integer square roots][1] and remainders of each
15
17
/// [`u8`](prim@u8) value. For example, `U8_ISQRT_WITH_REMAINDER[17]` will be
16
18
/// `(4, 1)` because the integer square root of 17 is 4 and because 17 is 1
@@ -96,6 +98,16 @@ macro_rules! signed_fn {
96
98
without modifying the original"]
97
99
#[ inline( always) ]
98
100
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
+
99
111
$UnsignedT( n as $UnsignedT) as $SignedT
100
112
}
101
113
} ;
You can’t perform that action at this time.
0 commit comments