Skip to main content

Module shl

Module shl 

Source
Expand description

Left-shifting a Float (multiplying it by a power of 2).

§shl

use malachite_base::num::basic::traits::{Infinity, Zero};
use malachite_float::Float;

assert_eq!(Float::ZERO << 10, 0);
assert_eq!(Float::INFINITY << 10, Float::INFINITY);
assert_eq!(
    (Float::from(std::f64::consts::PI) << 10u8).to_string(),
    "3216.990877275948"
);
assert_eq!(
    (Float::from(std::f64::consts::PI) << -10i8).to_string(),
    "0.003067961575771282"
);

assert_eq!(&Float::ZERO << 10, 0);
assert_eq!(&Float::INFINITY << 10, Float::INFINITY);
assert_eq!(
    (&Float::from(std::f64::consts::PI) << 10u8).to_string(),
    "3216.990877275948"
);
assert_eq!(
    (&Float::from(std::f64::consts::PI) << -10i8).to_string(),
    "0.003067961575771282"
);

§shl_assign

use malachite_base::num::basic::traits::{Infinity, Zero};
use malachite_float::Float;

let mut x = Float::ZERO;
x <<= 10;
assert_eq!(x, 0);

let mut x = Float::INFINITY;
x <<= 10;
assert_eq!(x, Float::INFINITY);

let mut x = Float::from(std::f64::consts::PI);
x <<= 10;
assert_eq!(x.to_string(), "3216.990877275948");

let mut x = Float::from(std::f64::consts::PI);
x <<= -10;
assert_eq!(x.to_string(), "0.003067961575771282");