std-method
Integer isqrt and checked_isqrt
Compute the floor of a nonnegative square root without a floating conversion. For signed input, use checked_isqrt if negative values are possible. Expected stdout (not executed): 7 Some(9) None Common mistake: Rounding a floating square root to the nearest integer when floor is required.
Formal Syntax & Structure
rust syntaxrust
n.isqrt(); signed.checked_isqrt()Working Example
Example Snippetrust
fn main() { println!("{}", 50u32.isqrt()); println!("{:?} {:?}", 81i32.checked_isqrt(), (-1i32).checked_isqrt());}