pub trait Sqrt {
// Required method
fn sqrt(self) -> Self;
}Expand description
平方根。
$\lfloor\sqrt{n}\rfloor$ を求める。
§Complexity
$O(\log(n))$ time.
Newton 法で $O(\log(\log(n)))$ time にするべき?
§Examples
use nekolib::math::Sqrt;
assert_eq!(0_i32.sqrt(), 0);
assert_eq!(9_i32.sqrt(), 3);
assert_eq!(12_i32.sqrt(), 3);
assert_eq!(16_i32.sqrt(), 4);
assert_eq!(u128::MAX.sqrt(), (1 << 64) - 1);ⓘ
use nekolib::math::Sqrt;
(-1_i32).sqrt();Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.