Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Square root of integer numbers

  • isqrt

  • integer_sqrt

  • There is a method called isqrt, but it is experimental.

  • There is a crate called integer-sqrt that provides a trait called IntegerSquareRoot and a method called integer_sqrt.

[package]
name = "sqrt-of-integer"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
integer-sqrt = "0.1.5"
use integer_sqrt::IntegerSquareRoot;

fn main() {
    let x = 16;

    println!("{}", x.integer_sqrt());
}