Module malachite_base::num::arithmetic::root
source · Expand description
Traits for taking the $n$th root of a number.
The traits are FloorRoot
, FloorRootAssign
,
CeilingRoot
, CeilingRootAssign
,
CheckedRoot
, RootRem
, and
RootAssignRem
.
§floor_root
use malachite_base::num::arithmetic::traits::FloorRoot;
assert_eq!(999u16.floor_root(3), 9);
assert_eq!(1000u16.floor_root(3), 10);
assert_eq!(1001u16.floor_root(3), 10);
assert_eq!(100000000000i64.floor_root(5), 158);
assert_eq!((-100000000000i64).floor_root(5), -159);
§floor_root_assign
use malachite_base::num::arithmetic::traits::FloorRootAssign;
let mut x = 999u16;
x.floor_root_assign(3);
assert_eq!(x, 9);
let mut x = 1000u16;
x.floor_root_assign(3);
assert_eq!(x, 10);
let mut x = 1001u16;
x.floor_root_assign(3);
assert_eq!(x, 10);
let mut x = 100000000000i64;
x.floor_root_assign(5);
assert_eq!(x, 158);
let mut x = -100000000000i64;
x.floor_root_assign(5);
assert_eq!(x, -159);
§ceiling_root
use malachite_base::num::arithmetic::traits::CeilingRoot;
assert_eq!(999u16.ceiling_root(3), 10);
assert_eq!(1000u16.ceiling_root(3), 10);
assert_eq!(1001u16.ceiling_root(3), 11);
assert_eq!(100000000000i64.ceiling_root(5), 159);
assert_eq!((-100000000000i64).ceiling_root(5), -158);
§ceiling_root_assign
use malachite_base::num::arithmetic::traits::CeilingRootAssign;
let mut x = 999u16;
x.ceiling_root_assign(3);
assert_eq!(x, 10);
let mut x = 1000u16;
x.ceiling_root_assign(3);
assert_eq!(x, 10);
let mut x = 1001u16;
x.ceiling_root_assign(3);
assert_eq!(x, 11);
let mut x = 100000000000i64;
x.ceiling_root_assign(5);
assert_eq!(x, 159);
let mut x = -100000000000i64;
x.ceiling_root_assign(5);
assert_eq!(x, -158);
§checked_root
use malachite_base::num::arithmetic::traits::CheckedRoot;
assert_eq!(999u16.checked_root(3), None);
assert_eq!(1000u16.checked_root(3), Some(10));
assert_eq!(1001u16.checked_root(3), None);
assert_eq!(100000000000i64.checked_root(5), None);
assert_eq!((-100000000000i64).checked_root(5), None);
assert_eq!(10000000000i64.checked_root(5), Some(100));
assert_eq!((-10000000000i64).checked_root(5), Some(-100));
§root_rem
use malachite_base::num::arithmetic::traits::RootRem;
assert_eq!(999u16.root_rem(3), (9, 270));
assert_eq!(1000u16.root_rem(3), (10, 0));
assert_eq!(1001u16.root_rem(3), (10, 1));
assert_eq!(100000000000u64.root_rem(5), (158, 1534195232));
§root_assign_rem
use malachite_base::num::arithmetic::traits::RootAssignRem;
let mut x = 999u16;
assert_eq!(x.root_assign_rem(3), 270);
assert_eq!(x, 9);
let mut x = 1000u16;
assert_eq!(x.root_assign_rem(3), 0);
assert_eq!(x, 10);
let mut x = 1001u16;
assert_eq!(x.root_assign_rem(3), 1);
assert_eq!(x, 10);
let mut x = 100000000000u64;
assert_eq!(x.root_assign_rem(5), 1534195232);
assert_eq!(x, 158);