Skip to main content

Sqrt

Trait Sqrt 

Source
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§

Source

fn sqrt(self) -> Self

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.

Implementations on Foreign Types§

Source§

impl Sqrt for i8

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for i16

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for i32

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for i64

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for i128

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for isize

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for u8

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for u16

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for u32

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for u64

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for u128

Source§

fn sqrt(self) -> Self

Source§

impl Sqrt for usize

Source§

fn sqrt(self) -> Self

Implementors§