Trait nekolib::math::sqrt::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

Implementations on Foreign Types§

source§

impl Sqrt for i8

source§

fn sqrt(self) -> Self

source§

impl Sqrt for isize

source§

fn sqrt(self) -> Self

source§

impl Sqrt for u128

source§

fn sqrt(self) -> Self

source§

impl Sqrt for u16

source§

fn sqrt(self) -> Self

source§

impl Sqrt for u64

source§

fn sqrt(self) -> Self

source§

impl Sqrt for i16

source§

fn sqrt(self) -> Self

source§

impl Sqrt for usize

source§

fn sqrt(self) -> Self

source§

impl Sqrt for u32

source§

fn sqrt(self) -> Self

source§

impl Sqrt for u8

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

Implementors§