Struct rug::float::SmallFloat [] [src]

#[repr(C)]
pub struct SmallFloat { /* fields omitted */ }

A small float that does not require any memory allocation.

This can be useful when you have a primitive number type but need a reference to a Float. The SmallFloat will have a precision according to the type of the primitive used to set its value.

  • i8, u8: the SmallFloat will have eight bits of precision.
  • i16, u16: the SmallFloat will have 16 bits of precision.
  • i32, u32: the SmallFloat will have 32 bits of precision.
  • i64, u64: the SmallFloat will have 64 bits of precision.
  • f32: the SmallFloat will have 24 bits of precision.
  • f64: the SmallFloat will have 53 bits of precision.

The SmallFloat type can be coerced to a Float, as it implements Deref with a Float target.

Examples

use rug::Float;
use rug::float::SmallFloat;
// `a` requires a heap allocation, has 53-bit precision
let mut a = Float::with_val(53, 250);
// `b` can reside on the stack
let b = SmallFloat::from(-100f64);
a += &*b;
assert_eq!(a, 150);
// another computation:
a *= &*b;
assert_eq!(a, -15000);

Methods

impl SmallFloat
[src]

[src]

Creates a SmallFloat with value 0.

Examples

use rug::float::SmallFloat;
let f = SmallFloat::new();
// Borrow f as if it were Float.
assert_eq!(*f, 0.0);

Methods from Deref<Target = Float>

[src]

Returns the precision.

Examples

use rug::Float;
let f = Float::new(53);
assert_eq!(f.prec(), 53);

[src]

Converts to an integer, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 13.7);
let i = match f.to_integer() {
    Some(i) => i,
    None => unreachable!(),
};
assert_eq!(i, 14);

[src]

Converts to an integer, applying the specified rounding method.

Examples

use rug::Float;
use rug::float::Round;
use std::cmp::Ordering;
let f = Float::with_val(53, 13.7);
let (i, dir) = match f.to_integer_round(Round::Down) {
    Some(i_dir) => i_dir,
    None => unreachable!(),
};
assert_eq!(i, 13);
assert_eq!(dir, Ordering::Less);

[src]

If the value is a finite number, returns an Integer and exponent such that self is exactly equal to the integer multiplied by two raised to the power of the exponent.

Examples

use rug::{Assign, Float};
use rug::float::Special;
let mut float = Float::with_val(16, 6.5);
// 6.5 in binary is 110.1
// Since the precision is 16 bits, this becomes
// 1101_0000_0000_0000 times two to the power of -12
let (int, exp) = float.to_integer_exp().unwrap();
assert_eq!(int, 0b1101_0000_0000_0000);
assert_eq!(exp, -13);

float.assign(0);
let (zero, _) = float.to_integer_exp().unwrap();
assert_eq!(zero, 0);

float.assign(Special::Infinity);
assert!(float.to_integer_exp().is_none());

[src]

If the value is a finite number, returns a Rational number preserving all the precision of the value.

Examples

use rug::{Float, Rational};
use rug::float::Round;
use std::str::FromStr;
use std::cmp::Ordering;

// Consider the number 123,456,789 / 10,000,000,000.
let res = Float::from_str_round("0.0123456789", 35, Round::Down);
let (f, f_rounding) = res.unwrap();
assert_eq!(f_rounding, Ordering::Less);
let r = Rational::from_str("123456789/10000000000").unwrap();
// Set fr to the value of f exactly.
let fr = f.to_rational().unwrap();
// Since f == fr and f was rounded down, r != fr.
assert_ne!(r, fr);
let (frf, frf_rounding) = Float::with_val_round(35, &fr, Round::Down);
assert_eq!(frf_rounding, Ordering::Equal);
assert_eq!(frf, f);
assert_eq!(format!("{:.9}", frf), "1.23456789e-2");

In the following example, the Float values can be represented exactly.

use rug::Float;

let large_f = Float::with_val(16, 6.5);
let large_r = large_f.to_rational().unwrap();
let small_f = Float::with_val(16, -0.125);
let small_r = small_f.to_rational().unwrap();

assert_eq!(*large_r.numer(), 13);
assert_eq!(*large_r.denom(), 2);
assert_eq!(*small_r.numer(), -1);
assert_eq!(*small_r.denom(), 8);

[src]

Converts to an i32, rounding to the nearest.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned. If the value is a NaN, None is returned.

Examples

use rug::{Assign, Float};
use std::{i32, u32};
let mut f = Float::with_val(53, -13.7);
assert_eq!(f.to_i32_saturating(), Some(-14));
f.assign(-1e40);
assert_eq!(f.to_i32_saturating(), Some(i32::MIN));
f.assign(u32::MAX);
assert_eq!(f.to_i32_saturating(), Some(i32::MAX));

[src]

Converts to an i32, applying the specified rounding method.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned. If the value is a NaN, None is returned.

Examples

use rug::Float;
use rug::float::Round;
let f = Float::with_val(53, -13.7);
assert_eq!(f.to_i32_saturating_round(Round::Up), Some(-13));

[src]

Converts to a u32, rounding to the nearest.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned. If the value is a NaN, None is returned.

Examples

use rug::{Assign, Float};
use std::u32;
let mut f = Float::with_val(53, 13.7);
assert_eq!(f.to_u32_saturating(), Some(14));
f.assign(-1);
assert_eq!(f.to_u32_saturating(), Some(0));
f.assign(1e40);
assert_eq!(f.to_u32_saturating(), Some(u32::MAX));

[src]

Converts to a u32, applying the specified rounding method.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned. If the value is a NaN, None is returned.

Examples

use rug::Float;
use rug::float::Round;
let f = Float::with_val(53, 13.7);
assert_eq!(f.to_u32_saturating_round(Round::Down), Some(13));

[src]

Converts to an f32, rounding to the nearest.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::{Assign, Float};
use std::f32;
let mut f = Float::with_val(53, 13.7);
assert_eq!(f.to_f32(), 13.7);
f.assign(1e300);
assert_eq!(f.to_f32(), f32::INFINITY);
f.assign(1e-300);
assert_eq!(f.to_f32(), 0.0);

[src]

Converts to an f32, applying the specified rounding method.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
use rug::float::Round;
use std::f32;
let f = Float::with_val(53, 1.0 + (-50f64).exp2());
assert_eq!(f.to_f32_round(Round::Up), 1.0 + f32::EPSILON);

[src]

Converts to an f64, rounding to the nearest.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::{Assign, Float};
use std::f64;
let mut f = Float::with_val(53, 13.7);
assert_eq!(f.to_f64(), 13.7);
f.assign(1e300);
f.square_mut();
assert_eq!(f.to_f64(), f64::INFINITY);

[src]

Converts to an f64, applying the specified rounding method.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
use rug::float::Round;
use std::f64;
// (2.0 ^ -90) + 1
let f: Float = Float::with_val(100, -90).exp2() + 1;
assert_eq!(f.to_f64_round(Round::Up), 1.0 + f64::EPSILON);

[src]

Converts to an f32 and an exponent, rounding to the nearest.

The returned f32 is in the range 0.5 ≤ x < 1.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
let zero = Float::new(64);
let (d0, exp0) = zero.to_f32_exp();
assert_eq!((d0, exp0), (0.0, 0));
let three_eighths = Float::with_val(64, 0.375);
let (d3_8, exp3_8) = three_eighths.to_f32_exp();
assert_eq!((d3_8, exp3_8), (0.75, -1));

[src]

Converts to an f32 and an exponent, applying the specified rounding method.

The returned f32 is in the range 0.5 ≤ x < 1.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
use rug::float::Round;
let frac_10_3 = Float::with_val(64, 10) / 3u32;
let (f_down, exp_down) = frac_10_3.to_f32_exp_round(Round::Down);
assert_eq!((f_down, exp_down), (0.8333333, 2));
let (f_up, exp_up) = frac_10_3.to_f32_exp_round(Round::Up);
assert_eq!((f_up, exp_up), (0.8333334, 2));

[src]

Converts to an f64 and an exponent, rounding to the nearest.

The returned f64 is in the range 0.5 ≤ x < 1.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
let zero = Float::new(64);
let (d0, exp0) = zero.to_f64_exp();
assert_eq!((d0, exp0), (0.0, 0));
let three_eighths = Float::with_val(64, 0.375);
let (d3_8, exp3_8) = three_eighths.to_f64_exp();
assert_eq!((d3_8, exp3_8), (0.75, -1));

[src]

Converts to an f64 and an exponent, applying the specified rounding method.

The returned f64 is in the range 0.5 ≤ x < 1.

If the value is too small or too large for the target type, the minimum or maximum value allowed is returned.

Examples

use rug::Float;
use rug::float::Round;
let frac_10_3 = Float::with_val(64, 10) / 3u32;
let (f_down, exp_down) = frac_10_3.to_f64_exp_round(Round::Down);
assert_eq!((f_down, exp_down), (0.8333333333333333, 2));
let (f_up, exp_up) = frac_10_3.to_f64_exp_round(Round::Up);
assert_eq!((f_up, exp_up), (0.8333333333333334, 2));

[src]

Returns a string representation of self for the specified radix rounding to the nearest.

The exponent is encoded in decimal. The output string will have enough precision such that reading it again will give the exact same number.

Examples

use rug::Float;
use rug::float::Special;
let neg_inf = Float::with_val(53, Special::NegInfinity);
assert_eq!(neg_inf.to_string_radix(10, None), "-inf");
assert_eq!(neg_inf.to_string_radix(16, None), "-@inf@");
let twentythree = Float::with_val(8, 23);
assert_eq!(twentythree.to_string_radix(10, None), "2.300e1");
assert_eq!(twentythree.to_string_radix(16, None), "1.70@1");
assert_eq!(twentythree.to_string_radix(10, Some(2)), "2.3e1");
assert_eq!(twentythree.to_string_radix(16, Some(4)), "1.700@1");

Panics

Panics if radix is less than 2 or greater than 36.

[src]

Returns a string representation of self for the specified radix applying the specified rounding method.

The exponent is encoded in decimal. The output string will have enough precision such that reading it again will give the exact same number.

Examples

use rug::Float;
use rug::float::Round;
let twentythree = Float::with_val(8, 23.3);
let down = twentythree.to_string_radix_round(10, Some(2), Round::Down);
assert_eq!(down, "2.3e1");
let up = twentythree.to_string_radix_round(10, Some(2), Round::Up);
assert_eq!(up, "2.4e1");

Panics

Panics if radix is less than 2 or greater than 36.

[src]

Borrows a negated copy of the Float.

The returned object implements Deref with a Float target. This method performs a shallow copy and negates it, and negation does not change the allocated data.

Examples

use rug::Float;
let f = Float::with_val(53, 4.2);
let neg_f = f.as_neg();
assert_eq!(*neg_f, -4.2);
// methods taking &self can be used on the returned object
let reneg_f = neg_f.as_neg();
assert_eq!(*reneg_f, 4.2);
assert_eq!(*reneg_f, f);

[src]

Borrows an absolute copy of the Float.

The returned object implements Deref with a Float target. This method performs a shallow copy and possibly negates it, and negation does not change the allocated data.

Examples

use rug::Float;
let f = Float::with_val(53, -4.2);
let abs_f = f.as_abs();
assert_eq!(*abs_f, 4.2);
// methods taking &self can be used on the returned object
let reabs_f = abs_f.as_abs();
assert_eq!(*reabs_f, 4.2);
assert_eq!(*reabs_f, *abs_f);

[src]

Borrows the Float as an ordered float of type OrdFloat.

Examples

use rug::Float;
use rug::float::Special;
use std::cmp::Ordering;

let nan_f = Float::with_val(53, Special::Nan);
let nan = nan_f.as_ord();
assert_eq!(nan.cmp(nan), Ordering::Equal);

let neg_inf_f = Float::with_val(53, Special::NegInfinity);
let neg_inf = neg_inf_f.as_ord();
assert_eq!(nan.cmp(neg_inf), Ordering::Less);

let zero_f = Float::with_val(53, Special::Zero);
let zero = zero_f.as_ord();
let neg_zero_f = Float::with_val(53, Special::NegZero);
let neg_zero = neg_zero_f.as_ord();
assert_eq!(zero.cmp(neg_zero), Ordering::Greater);

[src]

Returns true if self is an integer.

Examples

use rug::Float;
let mut f = Float::with_val(53, 13.5);
assert!(!f.is_integer());
f *= 2;
assert!(f.is_integer());

[src]

Returns true if self is not a number.

Examples

use rug::Float;
let mut f = Float::with_val(53, 0);
assert!(!f.is_nan());
f /= 0;
assert!(f.is_nan());

[src]

Returns true if self is plus or minus infinity.

Examples

use rug::Float;
let mut f = Float::with_val(53, 1);
assert!(!f.is_infinite());
f /= 0;
assert!(f.is_infinite());

[src]

Returns true if self is a finite number, that is neither NaN nor infinity.

Examples

use rug::Float;
let mut f = Float::with_val(53, 1);
assert!(f.is_finite());
f /= 0;
assert!(!f.is_finite());

[src]

Returns true if self is plus or minus zero.

Examples

use rug::{Assign, Float};
use rug::float::Special;
let mut f = Float::with_val(53, Special::Zero);
assert!(f.is_zero());
f.assign(Special::NegZero);
assert!(f.is_zero());
f += 1;
assert!(!f.is_zero());

[src]

Returns true if self is a normal number, that is neither NaN, nor infinity, nor zero. Note that Float cannot be subnormal.

Examples

use rug::{Assign, Float};
use rug::float::Special;
let mut f = Float::with_val(53, Special::Zero);
assert!(!f.is_normal());
f += 5.2;
assert!(f.is_normal());
f.assign(Special::Infinity);
assert!(!f.is_normal());
f.assign(Special::Nan);
assert!(!f.is_normal());

[src]

Returns the same result as self.partial_cmp(&0), but is faster.

Examples

use rug::{Assign, Float};
use rug::float::Special;
use std::cmp::Ordering;
let mut f = Float::with_val(53, Special::NegZero);
assert_eq!(f.cmp0(), Some(Ordering::Equal));
f += 5.2;
assert_eq!(f.cmp0(), Some(Ordering::Greater));
f.assign(Special::NegInfinity);
assert_eq!(f.cmp0(), Some(Ordering::Less));
f.assign(Special::Nan);
assert_eq!(f.cmp0(), None);

[src]

Compares the absolute values of self and other.

Examples

use rug::Float;
use std::cmp::Ordering;
let a = Float::with_val(53, -10);
let b = Float::with_val(53, 4);
assert_eq!(a.partial_cmp(&b), Some(Ordering::Less));
assert_eq!(a.cmp_abs(&b), Some(Ordering::Greater));

[src]

Returns the exponent of self if self is a normal number, otherwise None.

The significand is assumed to be in the range 0.5 ≤ x < 1.

Examples

use rug::{Assign, Float};
// -(2.0 ^ 32) == -(0.5 * 2 ^ 33)
let mut f = Float::with_val(53, -32f64.exp2());
assert_eq!(f.get_exp(), Some(33));
// 0.8 * 2 ^ -39
f.assign(0.8 * (-39f64).exp2());
assert_eq!(f.get_exp(), Some(-39));
f.assign(0);
assert_eq!(f.get_exp(), None);

[src]

Returns true if the value is positive, +0 or NaN without a negative sign.

Examples

use rug::Float;
let pos = Float::with_val(53, 1.0);
let neg = Float::with_val(53, -1.0);
assert!(pos.is_sign_positive());
assert!(!neg.is_sign_positive());

[src]

Returns true if the value is negative, −0 or NaN with a negative sign.

Examples

use rug::Float;
let neg = Float::with_val(53, -1.0);
let pos = Float::with_val(53, 1.0);
assert!(neg.is_sign_negative());
assert!(!pos.is_sign_negative());

[src]

Computes the square, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 5.0);
let square = f.square();
assert_eq!(square, 25.0);

[src]

Computes the square.

Examples

use rug::Float;
let f = Float::with_val(53, 5.0);
let r = f.square_ref();
let square = Float::with_val(53, r);
assert_eq!(square, 25.0);

[src]

Computes the square root, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 25.0);
let sqrt = f.sqrt();
assert_eq!(sqrt, 5.0);

[src]

Computes the square root.

Examples

use rug::Float;
let f = Float::with_val(53, 25.0);
let r = f.sqrt_ref();
let sqrt = Float::with_val(53, r);
assert_eq!(sqrt, 5.0);

[src]

Computes the reciprocal square root, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 16.0);
let recip_sqrt = f.recip_sqrt();
assert_eq!(recip_sqrt, 0.25);

[src]

Computes the reciprocal square root.

Examples

use rug::Float;
let f = Float::with_val(53, 16.0);
let r = f.recip_sqrt_ref();
let recip_sqrt = Float::with_val(53, r);
assert_eq!(recip_sqrt, 0.25);

[src]

Computes the cube root, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 125.0);
let cbrt = f.cbrt();
assert_eq!(cbrt, 5.0);

[src]

Computes the cube root.

Examples

use rug::Float;
let f = Float::with_val(53, 125.0);
let r = f.cbrt_ref();
let cbrt = Float::with_val(53, r);
assert_eq!(cbrt, 5.0);

[src]

Computes the kth root, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 625.0);
let root = f.root(4);
assert_eq!(root, 5.0);

[src]

Computes the kth root.

Examples

use rug::Float;
let f = Float::with_val(53, 625.0);
let r = f.root_ref(4);
let root = Float::with_val(53, r);
assert_eq!(root, 5.0);

[src]

Computes the absolute value.

Examples

use rug::Float;
let f = Float::with_val(53, -23.5);
let abs = f.abs();
assert_eq!(abs, 23.5);

[src]

Computes the absolute value.

Examples

use rug::Float;
let f = Float::with_val(53, -23.5);
let r = f.abs_ref();
let abs = Float::with_val(53, r);
assert_eq!(abs, 23.5);

[src]

Clamps the value within the specified bounds, rounding to the nearest.

Examples

use rug::Float;
let min = -1.5;
let max = 1.5;
let too_small = Float::with_val(53, -2.5);
let clamped1 = too_small.clamp(&min, &max);
assert_eq!(clamped1, -1.5);
let in_range = Float::with_val(53, 0.5);
let clamped2 = in_range.clamp(&min, &max);
assert_eq!(clamped2, 0.5);

Panics

Panics if the maximum value is less than the minimum value, unless assigning any of them to self produces the same value with the same rounding direction.

[src]

Clamps the value within the specified bounds.

The returned reference is self if the value is within the bounds, min if the value is less than the minimum, and max if the value is larger than the maximum.

Examples

use rug::Float;
let min = -1.5;
let max = 1.5;
let too_small = Float::with_val(53, -2.5);
let r1 = too_small.clamp_ref(&min, &max);
let clamped1 = Float::with_val(53, r1);
assert_eq!(clamped1, -1.5);
let in_range = Float::with_val(53, 0.5);
let r2 = in_range.clamp_ref(&min, &max);
let clamped2 = Float::with_val(53, r2);
assert_eq!(clamped2, 0.5);

Panics

Panics if the maximum value is less than the minimum value, unless assigning any of them to the target produces the same value with the same rounding direction.

[src]

Computes the reciprocal, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, -0.25);
let recip = f.recip();
assert_eq!(recip, -4.0);

[src]

Computes the reciprocal.

Examples

use rug::Float;
let f = Float::with_val(53, -0.25);
let r = f.recip_ref();
let recip = Float::with_val(53, r);
assert_eq!(recip, -4.0);

[src]

Finds the minimum, rounding to the nearest.

Examples

use rug::Float;
let a = Float::with_val(53, 5.2);
let b = Float::with_val(53, -2);
let min = a.min(&b);
assert_eq!(min, -2);

[src]

Finds the minimum.

Examples

use rug::Float;
let a = Float::with_val(53, 5.2);
let b = Float::with_val(53, -2);
let r = a.min_ref(&b);
let min = Float::with_val(53, r);
assert_eq!(min, -2);

[src]

Finds the maximum, rounding to the nearest.

Examples

use rug::Float;
let a = Float::with_val(53, 5.2);
let b = Float::with_val(53, 12.5);
let max = a.max(&b);
assert_eq!(max, 12.5);

[src]

Finds the maximum.

Examples

use rug::Float;
let a = Float::with_val(53, 5.2);
let b = Float::with_val(53, 12.5);
let r = a.max_ref(&b);
let max = Float::with_val(53, r);
assert_eq!(max, 12.5);

[src]

Computes the positive difference between self and other, rounding to the nearest.

The positive difference is selfother if self > other, zero if selfother, or NaN if any operand is NaN.

Examples

use rug::Float;
let a = Float::with_val(53, 12.5);
let b = Float::with_val(53, 7.3);
let diff1 = a.positive_diff(&b);
assert_eq!(diff1, 5.2);
let diff2 = diff1.positive_diff(&b);
assert_eq!(diff2, 0);

[src]

Computes the positive difference.

The positive difference is selfother if self > other, zero if selfother, or NaN if any operand is NaN.

Examples

use rug::Float;
let a = Float::with_val(53, 12.5);
let b = Float::with_val(53, 7.3);
let rab = a.positive_diff_ref(&b);
let ab = Float::with_val(53, rab);
assert_eq!(ab, 5.2);
let rba = b.positive_diff_ref(&a);
let ba = Float::with_val(53, rba);
assert_eq!(ba, 0);

[src]

Computes the natural logarithm, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let ln = f.ln();
let expected = 0.4055_f64;
assert!((ln - expected).abs() < 0.0001);

[src]

Computes the natural logarithm.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let ln = Float::with_val(53, f.ln_ref());
let expected = 0.4055_f64;
assert!((ln - expected).abs() < 0.0001);

[src]

Computes the logarithm to base 2, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let log2 = f.log2();
let expected = 0.5850_f64;
assert!((log2 - expected).abs() < 0.0001);

[src]

Computes the logarithm to base 2.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let log2 = Float::with_val(53, f.log2_ref());
let expected = 0.5850_f64;
assert!((log2 - expected).abs() < 0.0001);

[src]

Computes the logarithm to base 10, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let log10 = f.log10();
let expected = 0.1761_f64;
assert!((log10 - expected).abs() < 0.0001);

[src]

Computes the logarithm to base 10.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let log10 = Float::with_val(53, f.log10_ref());
let expected = 0.1761_f64;
assert!((log10 - expected).abs() < 0.0001);

[src]

Computes the exponential, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp = f.exp();
let expected = 4.4817_f64;
assert!((exp - expected).abs() < 0.0001);

[src]

Computes the exponential.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp = Float::with_val(53, f.exp_ref());
let expected = 4.4817_f64;
assert!((exp - expected).abs() < 0.0001);

[src]

Computes 2 to the power of self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp2 = f.exp2();
let expected = 2.8284_f64;
assert!((exp2 - expected).abs() < 0.0001);

[src]

Computes 2 to the power of the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp2 = Float::with_val(53, f.exp2_ref());
let expected = 2.8284_f64;
assert!((exp2 - expected).abs() < 0.0001);

[src]

Computes 10 to the power of self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp10 = f.exp10();
let expected = 31.6228_f64;
assert!((exp10 - expected).abs() < 0.0001);

[src]

Computes 10 to the power of the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.5);
let exp10 = Float::with_val(53, f.exp10_ref());
let expected = 31.6228_f64;
assert!((exp10 - expected).abs() < 0.0001);

[src]

Computes the sine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sin = f.sin();
let expected = 0.9490_f64;
assert!((sin - expected).abs() < 0.0001);

[src]

Computes the sine.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sin = Float::with_val(53, f.sin_ref());
let expected = 0.9490_f64;
assert!((sin - expected).abs() < 0.0001);

[src]

Computes the cosine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cos = f.cos();
let expected = 0.3153_f64;
assert!((cos - expected).abs() < 0.0001);

[src]

Computes the cosine.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cos = Float::with_val(53, f.cos_ref());
let expected = 0.3153_f64;
assert!((cos - expected).abs() < 0.0001);

[src]

Computes the tangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let tan = f.tan();
let expected = 3.0096_f64;
assert!((tan - expected).abs() < 0.0001);

[src]

Computes the tangent.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let tan = Float::with_val(53, f.tan_ref());
let expected = 3.0096_f64;
assert!((tan - expected).abs() < 0.0001);

[src]

Computes the sine and cosine of self, rounding to the nearest.

The sine is stored in self and keeps its precision, while the cosine is stored in cos keeping its precision.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let (sin, cos) = f.sin_cos(Float::new(53));
let expected_sin = 0.9490_f64;
let expected_cos = 0.3153_f64;
assert!((sin - expected_sin).abs() < 0.0001);
assert!((cos - expected_cos).abs() < 0.0001);

[src]

Computes the sine and cosine.

Examples

use rug::{Assign, Float};
use rug::float::Round;
use rug::ops::AssignRound;
use std::cmp::Ordering;
let phase = Float::with_val(53, 1.25);
let sin_cos = phase.sin_cos_ref();

let (mut sin, mut cos) = (Float::new(53), Float::new(53));
(&mut sin, &mut cos).assign(sin_cos);
let expected_sin = 0.9490_f64;
let expected_cos = 0.3153_f64;
assert!((sin - expected_sin).abs() < 0.0001);
assert!((cos - expected_cos).abs() < 0.0001);

// using 4 significant bits: sin = 0.9375
// using 4 significant bits: cos = 0.3125
let (mut sin_4, mut cos_4) = (Float::new(4), Float::new(4));
let (dir_sin, dir_cos) = (&mut sin_4, &mut cos_4)
    .assign_round(sin_cos, Round::Nearest);
assert_eq!(sin_4, 0.9375);
assert_eq!(dir_sin, Ordering::Less);
assert_eq!(cos_4, 0.3125);
assert_eq!(dir_cos, Ordering::Less);

[src]

Computes the secant, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sec = f.sec();
let expected = 3.1714_f64;
assert!((sec - expected).abs() < 0.0001);

[src]

Computes the secant.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sec = Float::with_val(53, f.sec_ref());
let expected = 3.1714_f64;
assert!((sec - expected).abs() < 0.0001);

[src]

Computes the cosecant, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let csc = f.csc();
let expected = 1.0538_f64;
assert!((csc - expected).abs() < 0.0001);

[src]

Computes the cosecant.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let csc = Float::with_val(53, f.csc_ref());
let expected = 1.0538_f64;
assert!((csc - expected).abs() < 0.0001);

[src]

Computes the cotangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cot = f.cot();
let expected = 0.3323_f64;
assert!((cot - expected).abs() < 0.0001);

[src]

Computes the cotangent.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cot = Float::with_val(53, f.cot_ref());
let expected = 0.3323_f64;
assert!((cot - expected).abs() < 0.0001);

[src]

Computes the arc-sine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let asin = f.asin();
let expected = -0.8481_f64;
assert!((asin - expected).abs() < 0.0001);

[src]

Computes the arc-sine.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let asin = Float::with_val(53, f.asin_ref());
let expected = -0.8481_f64;
assert!((asin - expected).abs() < 0.0001);

[src]

Computes the arc-cosine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let acos = f.acos();
let expected = 2.4189_f64;
assert!((acos - expected).abs() < 0.0001);

[src]

Computes the arc-cosine.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let acos = Float::with_val(53, f.acos_ref());
let expected = 2.4189_f64;
assert!((acos - expected).abs() < 0.0001);

[src]

Computes the arc-tangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let atan = f.atan();
let expected = -0.6435_f64;
assert!((atan - expected).abs() < 0.0001);

[src]

Computes the arc-tangent.

Examples

use rug::Float;
let f = Float::with_val(53, -0.75);
let atan = Float::with_val(53, f.atan_ref());
let expected = -0.6435_f64;
assert!((atan - expected).abs() < 0.0001);

[src]

Computes the arc-tangent2 of self and x, rounding to the nearest.

This is similar to the arc-tangent of self / x, but has an output range of 2π rather than π.

Examples

use rug::Float;
let y = Float::with_val(53, 3.0);
let x = Float::with_val(53, -4.0);
let atan2 = y.atan2(&x);
let expected = 2.4981_f64;
assert!((atan2 - expected).abs() < 0.0001);

[src]

Computes the arc-tangent.

This is similar to the arc-tangent of self / x, but has an output range of 2π rather than π.

Examples

use rug::Float;
let y = Float::with_val(53, 3.0);
let x = Float::with_val(53, -4.0);
let r = y.atan2_ref(&x);
let atan2 = Float::with_val(53, r);
let expected = 2.4981_f64;
assert!((atan2 - expected).abs() < 0.0001);

[src]

Computes the hyperbolic sine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sinh = f.sinh();
let expected = 1.6019_f64;
assert!((sinh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic sine.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sinh = Float::with_val(53, f.sinh_ref());
let expected = 1.6019_f64;
assert!((sinh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cosine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cosh = f.cosh();
let expected = 1.8884_f64;
assert!((cosh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cosine.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let cosh = Float::with_val(53, f.cosh_ref());
let expected = 1.8884_f64;
assert!((cosh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic tangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let tanh = f.tanh();
let expected = 0.8483_f64;
assert!((tanh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic tangent.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let tanh = Float::with_val(53, f.tanh_ref());
let expected = 0.8483_f64;
assert!((tanh - expected).abs() < 0.0001);

[src]

Computes the hyperbolic sine and cosine of self, rounding to the nearest.

The sine is stored in self and keeps its precision, while the cosine is stored in cos keeping its precision.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let (sinh, cosh) = f.sinh_cosh(Float::new(53));
let expected_sinh = 1.6019_f64;
let expected_cosh = 1.8884_f64;
assert!((sinh - expected_sinh).abs() < 0.0001);
assert!((cosh - expected_cosh).abs() < 0.0001);

[src]

Computes the hyperbolic sine and cosine.

Examples

use rug::{Assign, Float};
use rug::float::Round;
use rug::ops::AssignRound;
use std::cmp::Ordering;
let phase = Float::with_val(53, 1.25);
let sinh_cosh = phase.sinh_cosh_ref();

let (mut sinh, mut cosh) = (Float::new(53), Float::new(53));
(&mut sinh, &mut cosh).assign(sinh_cosh);
let expected_sinh = 1.6019_f64;
let expected_cosh = 1.8884_f64;
assert!((sinh - expected_sinh).abs() < 0.0001);
assert!((cosh - expected_cosh).abs() < 0.0001);

// using 4 significant bits: sin = 1.625
// using 4 significant bits: cos = 1.875
let (mut sinh_4, mut cosh_4) = (Float::new(4), Float::new(4));
let (dir_sinh, dir_cosh) = (&mut sinh_4, &mut cosh_4)
    .assign_round(sinh_cosh, Round::Nearest);
assert_eq!(sinh_4, 1.625);
assert_eq!(dir_sinh, Ordering::Greater);
assert_eq!(cosh_4, 1.875);
assert_eq!(dir_cosh, Ordering::Less);

[src]

Computes the hyperbolic secant, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sech = f.sech();
let expected = 0.5295_f64;
assert!((sech - expected).abs() < 0.0001);

[src]

Computes the hyperbolic secant.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let sech = Float::with_val(53, f.sech_ref());
let expected = 0.5295_f64;
assert!((sech - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cosecant, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let csch = f.csch();
let expected = 0.6243_f64;
assert!((csch - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cosecant.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let csch = Float::with_val(53, f.csch_ref());
let expected = 0.6243_f64;
assert!((csch - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cotangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let coth = f.coth();
let expected = 1.1789_f64;
assert!((coth - expected).abs() < 0.0001);

[src]

Computes the hyperbolic cotangent.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let coth = Float::with_val(53, f.coth_ref());
let expected = 1.1789_f64;
assert!((coth - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic sine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let asinh = f.asinh();
let expected = 1.0476_f64;
assert!((asinh - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic sine.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let asinh = Float::with_val(53, f.asinh_ref());
let expected = 1.0476_f64;
assert!((asinh - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic cosine, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let acosh = f.acosh();
let expected = 0.6931_f64;
assert!((acosh - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic cosine

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let acosh = Float::with_val(53, f.acosh_ref());
let expected = 0.6931_f64;
assert!((acosh - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic tangent, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 0.75);
let atanh = f.atanh();
let expected = 0.9730_f64;
assert!((atanh - expected).abs() < 0.0001);

[src]

Computes the inverse hyperbolic tangent.

Examples

use rug::Float;
let f = Float::with_val(53, 0.75);
let atanh = Float::with_val(53, f.atanh_ref());
let expected = 0.9730_f64;
assert!((atanh - expected).abs() < 0.0001);

[src]

Computes the natural logarithm of one plus self, rounding to the nearest.

Examples

use rug::Float;
let two_to_m10 = (-10f64).exp2();
let f = Float::with_val(53, 1.5 * two_to_m10);
let ln_1p = f.ln_1p();
let expected = 1.4989_f64 * two_to_m10;
assert!((ln_1p - expected).abs() < 0.0001 * two_to_m10);

[src]

Computes the natural logorithm of one plus the value.

Examples

use rug::Float;
let two_to_m10 = (-10f64).exp2();
let f = Float::with_val(53, 1.5 * two_to_m10);
let ln_1p = Float::with_val(53, f.ln_1p_ref());
let expected = 1.4989_f64 * two_to_m10;
assert!((ln_1p - expected).abs() < 0.0001 * two_to_m10);

[src]

Subtracts one from the exponential of self, rounding to the nearest.

Examples

use rug::Float;
let two_to_m10 = (-10f64).exp2();
let f = Float::with_val(53, 1.5 * two_to_m10);
let exp_m1 = f.exp_m1();
let expected = 1.5011_f64 * two_to_m10;
assert!((exp_m1 - expected).abs() < 0.0001 * two_to_m10);

[src]

Computes one less than the exponential of the value.

Examples

use rug::Float;
let two_to_m10 = (-10f64).exp2();
let f = Float::with_val(53, 1.5 * two_to_m10);
let exp_m1 = Float::with_val(53, f.exp_m1_ref());
let expected = 1.5011_f64 * two_to_m10;
assert!((exp_m1 - expected).abs() < 0.0001 * two_to_m10);

[src]

Computes the exponential integral, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let eint = f.eint();
let expected = 2.5810_f64;
assert!((eint - expected).abs() < 0.0001);

[src]

Computes the exponential integral.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let eint = Float::with_val(53, f.eint_ref());
let expected = 2.5810_f64;
assert!((eint - expected).abs() < 0.0001);

[src]

Computes the real part of the dilogarithm of self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let li2 = f.li2();
let expected = 2.1902_f64;
assert!((li2 - expected).abs() < 0.0001);

[src]

Computes the real part of the dilogarithm of the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let li2 = Float::with_val(53, f.li2_ref());
let expected = 2.1902_f64;
assert!((li2 - expected).abs() < 0.0001);

[src]

Computes the value of the Gamma function on self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let gamma = f.gamma();
let expected = 0.9064_f64;
assert!((gamma - expected).abs() < 0.0001);

[src]

Computes the Gamma function on the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let gamma = Float::with_val(53, f.gamma_ref());
let expected = 0.9064_f64;
assert!((gamma - expected).abs() < 0.0001);

[src]

Computes the logarithm of the Gamma function on self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let ln_gamma = f.ln_gamma();
let expected = -0.0983_f64;
assert!((ln_gamma - expected).abs() < 0.0001);

[src]

Computes the logarithm of the Gamma function on the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let ln_gamma = Float::with_val(53, f.ln_gamma_ref());
let expected = -0.0983_f64;
assert!((ln_gamma - expected).abs() < 0.0001);

[src]

Computes the logarithm of the absolute value of the Gamma function on self, rounding to the nearest.

Returns Ordering::Less if the Gamma function is negative, or Ordering::Greater if the Gamma function is positive.

Examples

use rug::Float;
use rug::float::Constant;
use std::cmp::Ordering;

// gamma of 1/2 is sqrt(pi)
let ln_gamma_64 = Float::with_val(64, Constant::Pi).sqrt().ln();

let f = Float::with_val(53, 0.5);
let (ln_gamma, sign) = f.ln_abs_gamma();
// gamma of 1/2 is positive
assert_eq!(sign, Ordering::Greater);
// check to 53 significant bits
assert_eq!(ln_gamma, Float::with_val(53, &ln_gamma_64));

If the Gamma function is negative, the sign returned is Ordering::Less.

use rug::Float;
use rug::float::Constant;
use std::cmp::Ordering;

// gamma of -1/2 is -2 * sqrt(pi)
let abs_gamma_64 = Float::with_val(64, Constant::Pi).sqrt() * 2u32;
let ln_gamma_64 = abs_gamma_64.ln();

let f = Float::with_val(53, -0.5);
let (ln_gamma, sign) = f.ln_abs_gamma();
// gamma of -1/2 is negative
assert_eq!(sign, Ordering::Less);
// check to 53 significant bits
assert_eq!(ln_gamma, Float::with_val(53, &ln_gamma_64));

[src]

Computes the logarithm of the absolute value of the Gamma function on val.

Examples

use rug::{Assign, Float};
use rug::float::Constant;
use std::cmp::Ordering;

let neg1_2 = Float::with_val(53, -0.5);
// gamma of -1/2 is -2 * sqrt(pi)
let abs_gamma_64 = Float::with_val(64, Constant::Pi).sqrt() * 2u32;
let ln_gamma_64 = abs_gamma_64.ln();

// Assign rounds to the nearest
let r = neg1_2.ln_abs_gamma_ref();
let (mut f, mut sign) = (Float::new(53), Ordering::Equal);
(&mut f, &mut sign).assign(r);
// gamma of -1/2 is negative
assert_eq!(sign, Ordering::Less);
// check to 53 significant bits
assert_eq!(f, Float::with_val(53, &ln_gamma_64));

[src]

Computes the value of the Digamma function on self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let digamma = f.digamma();
let expected = -0.2275_f64;
assert!((digamma - expected).abs() < 0.0001);

[src]

Computes the Digamma function on the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let digamma = Float::with_val(53, f.digamma_ref());
let expected = -0.2275_f64;
assert!((digamma - expected).abs() < 0.0001);

[src]

Computes the value of the Riemann Zeta function on self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let zeta = f.zeta();
let expected = 4.5951_f64;
assert!((zeta - expected).abs() < 0.0001);

[src]

Computes the Riemann Zeta function on the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let zeta = Float::with_val(53, f.zeta_ref());
let expected = 4.5951_f64;
assert!((zeta - expected).abs() < 0.0001);

[src]

Computes the value of the error function, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let erf = f.erf();
let expected = 0.9229_f64;
assert!((erf - expected).abs() < 0.0001);

[src]

Computes the error function.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let erf = Float::with_val(53, f.erf_ref());
let expected = 0.9229_f64;
assert!((erf - expected).abs() < 0.0001);

[src]

Computes the value of the complementary error function, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let erfc = f.erfc();
let expected = 0.0771_f64;
assert!((erfc - expected).abs() < 0.0001);

[src]

Computes the complementary error function.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let erfc = Float::with_val(53, f.erfc_ref());
let expected = 0.0771_f64;
assert!((erfc - expected).abs() < 0.0001);

[src]

Computes the value of the first kind Bessel function of order 0, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j0 = f.j0();
let expected = 0.6459_f64;
assert!((j0 - expected).abs() < 0.0001);

[src]

Computes the first kind Bessel function of order 0.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j0 = Float::with_val(53, f.j0_ref());
let expected = 0.6459_f64;
assert!((j0 - expected).abs() < 0.0001);

[src]

Computes the value of the first kind Bessel function of order 1, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j1 = f.j1();
let expected = 0.5106_f64;
assert!((j1 - expected).abs() < 0.0001);

[src]

Computes the first kind Bessel function of order 1.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j1 = Float::with_val(53, f.j1_ref());
let expected = 0.5106_f64;
assert!((j1 - expected).abs() < 0.0001);

[src]

Computes the value of the first kind Bessel function of order n, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j2 = f.jn(2);
let expected = 0.1711_f64;
assert!((j2 - expected).abs() < 0.0001);

[src]

Computes the first kind Bessel function of order n.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let j2 = Float::with_val(53, f.jn_ref(2));
let expected = 0.1711_f64;
assert!((j2 - expected).abs() < 0.0001);

[src]

Computes the value of the second kind Bessel function of order 0, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y0 = f.y0();
let expected = 0.2582_f64;
assert!((y0 - expected).abs() < 0.0001);

[src]

Computes the second kind Bessel function of order 0.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y0 = Float::with_val(53, f.y0_ref());
let expected = 0.2582_f64;
assert!((y0 - expected).abs() < 0.0001);

[src]

Computes the value of the second kind Bessel function of order 1, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y1 = f.y1();
let expected = -0.5844_f64;
assert!((y1 - expected).abs() < 0.0001);

[src]

Computes the second kind Bessel function of order 1.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y1 = Float::with_val(53, f.y1_ref());
let expected = -0.5844_f64;
assert!((y1 - expected).abs() < 0.0001);

[src]

Computes the value of the second kind Bessel function of order n, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y2 = f.yn(2);
let expected = -1.1932_f64;
assert!((y2 - expected).abs() < 0.0001);

[src]

Computes the second kind Bessel function of order n.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let y2 = Float::with_val(53, f.yn_ref(2));
let expected = -1.1932_f64;
assert!((y2 - expected).abs() < 0.0001);

[src]

Computes the arithmetic-geometric mean of self and other, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let g = Float::with_val(53, 3.75);
let agm = f.agm(&g);
let expected = 2.3295_f64;
assert!((agm - expected).abs() < 0.0001);

[src]

Computes the arithmetic-geometric mean.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let g = Float::with_val(53, 3.75);
let agm = Float::with_val(53, f.agm_ref(&g));
let expected = 2.3295_f64;
assert!((agm - expected).abs() < 0.0001);

[src]

Computes the Euclidean norm of self and other, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let g = Float::with_val(53, 3.75);
let hypot = f.hypot(&g);
let expected = 3.9528_f64;
assert!((hypot - expected).abs() < 0.0001);

[src]

Computes the Euclidean norm.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let g = Float::with_val(53, 3.75);
let hypot = Float::with_val(53, f.hypot_ref(&g));
let expected = 3.9528_f64;
assert!((hypot - expected).abs() < 0.0001);

[src]

Computes the value of the Airy function Ai on self, rounding to the nearest.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let ai = f.ai();
let expected = 0.0996_f64;
assert!((ai - expected).abs() < 0.0001);

[src]

Computes the Airy function Ai on the value.

Examples

use rug::Float;
let f = Float::with_val(53, 1.25);
let ai = Float::with_val(53, f.ai_ref());
let expected = 0.0996_f64;
assert!((ai - expected).abs() < 0.0001);

[src]

Rounds up to the next higher integer.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let ceil1 = f1.ceil();
assert_eq!(ceil1, -23);
let f2 = Float::with_val(53, 23.75);
let ceil2 = f2.ceil();
assert_eq!(ceil2, 24);

[src]

Rounds up to the next higher integer. The result may be rounded again when assigned to the target.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let ceil1 = Float::with_val(53, f1.ceil_ref());
assert_eq!(ceil1, -23);
let f2 = Float::with_val(53, 23.75);
let ceil2 = Float::with_val(53, f2.ceil_ref());
assert_eq!(ceil2, 24);

[src]

Rounds down to the next lower integer.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let floor1 = f1.floor();
assert_eq!(floor1, -24);
let f2 = Float::with_val(53, 23.75);
let floor2 = f2.floor();
assert_eq!(floor2, 23);

[src]

Rounds down to the next lower integer. The result may be rounded again when assigned to the target.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let floor1 = Float::with_val(53, f1.floor_ref());
assert_eq!(floor1, -24);
let f2 = Float::with_val(53, 23.75);
let floor2 = Float::with_val(53, f2.floor_ref());
assert_eq!(floor2, 23);

[src]

Rounds to the nearest integer, rounding half-way cases away from zero.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let round1 = f1.round();
assert_eq!(round1, -24);
let f2 = Float::with_val(53, 23.75);
let round2 = f2.round();
assert_eq!(round2, 24);

[src]

Rounds to the nearest integer, rounding half-way cases away from zero. The result may be rounded again when assigned to the target.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let round1 = Float::with_val(53, f1.round_ref());
assert_eq!(round1, -24);
let f2 = Float::with_val(53, 23.75);
let round2 = Float::with_val(53, f2.round_ref());
assert_eq!(round2, 24);

Double rounding may happen when assigning to a target with a precision less than the number of significant bits for the truncated integer.

use rug::Float;
use rug::float::Round;
use rug::ops::AssignRound;
let f = Float::with_val(53, 6.5);
// 6.5 (binary 110.1) is rounded to 7 (binary 111)
let r = f.round_ref();
// use only 2 bits of precision in destination
let mut dst = Float::new(2);
// 7 (binary 111) is rounded to 8 (binary 1000) by
// round-even rule in order to store in 2-bit Float, even
// though 6 (binary 110) is closer to original 6.5).
dst.assign_round(r, Round::Nearest);
assert_eq!(dst, 8);

[src]

Rounds to the next integer towards zero.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let trunc1 = f1.trunc();
assert_eq!(trunc1, -23);
let f2 = Float::with_val(53, 23.75);
let trunc2 = f2.trunc();
assert_eq!(trunc2, 23);

[src]

Rounds to the next integer towards zero. The result may be rounded again when assigned to the target.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let trunc1 = Float::with_val(53, f1.trunc_ref());
assert_eq!(trunc1, -23);
let f2 = Float::with_val(53, 23.75);
let trunc2 = Float::with_val(53, f2.trunc_ref());
assert_eq!(trunc2, 23);

[src]

Gets the fractional part of the number.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let fract1 = f1.fract();
assert_eq!(fract1, -0.75);
let f2 = Float::with_val(53, 23.75);
let fract2 = f2.fract();
assert_eq!(fract2, 0.75);

[src]

Gets the fractional part of the number.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let fract1 = Float::with_val(53, f1.fract_ref());
assert_eq!(fract1, -0.75);
let f2 = Float::with_val(53, 23.75);
let fract2 = Float::with_val(53, f2.fract_ref());
assert_eq!(fract2, 0.75);

[src]

Gets the integer and fractional parts of the number, rounding to the nearest.

The integer part is stored in self and keeps its precision, while the fractional part is stored in fract keeping its precision.

Examples

use rug::Float;
let f1 = Float::with_val(53, -23.75);
let (trunc1, fract1) = f1.trunc_fract(Float::new(53));
assert_eq!(trunc1, -23);
assert_eq!(fract1, -0.75);
let f2 = Float::with_val(53, 23.75);
let (trunc2, fract2) = f2.trunc_fract(Float::new(53));
assert_eq!(trunc2, 23);
assert_eq!(fract2, 0.75);

[src]

Gets the integer and fractional parts of the number.

Examples

use rug::{Assign, Float};
let f1 = Float::with_val(53, -23.75);
let r1 = f1.trunc_fract_ref();
let (mut trunc1, mut fract1) = (Float::new(53), Float::new(53));
(&mut trunc1, &mut fract1).assign(r1);
assert_eq!(trunc1, -23);
assert_eq!(fract1, -0.75);
let f2 = Float::with_val(53, -23.75);
let r2 = f2.trunc_fract_ref();
let (mut trunc2, mut fract2) = (Float::new(53), Float::new(53));
(&mut trunc2, &mut fract2).assign(r2);
assert_eq!(trunc2, -23);
assert_eq!(fract2, -0.75);

Trait Implementations

impl Default for SmallFloat
[src]

[src]

Returns the "default value" for a type. Read more

impl Deref for SmallFloat
[src]

The resulting type after dereferencing.

[src]

Dereferences the value.

impl<T> From<T> for SmallFloat where
    SmallFloat: Assign<T>, 
[src]

[src]

Performs the conversion.

impl Assign<i8> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<i16> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<i32> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<i64> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<u8> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<u16> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<u32> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<u64> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<f32> for SmallFloat
[src]

[src]

Peforms the assignement. Read more

impl Assign<f64> for SmallFloat
[src]

[src]

Peforms the assignement. Read more