pub fn int_sqrt_floor<T: PrimInt>(n: T) -> T
Expand description

Compute square root of integers using Newtons method. Returns the biggest integer which is smaller or equal to the actual square root of n. Similar to (i as f64).sqrt().floor() as T but without type conversions.

See: https://en.wikipedia.org/wiki/Integer_square_root

Panics

Panics when given a negative number.

Example

use iron_shapes::math::int_sqrt_floor;
assert_eq!(int_sqrt_floor(16), 4);
assert_eq!(int_sqrt_floor(17), 4);
assert_eq!(int_sqrt_floor(24), 4);
assert_eq!(int_sqrt_floor(25), 5);