Skip to main content

RadixFloat

Struct RadixFloat 

Source
pub struct RadixFloat { /* private fields */ }
Expand description

A floating-point value with an associated parse/format radix.

Implementations§

Source§

impl RadixFloat

Source

pub fn new(value: ExactNum, radix: Radix) -> Result<RadixFloat, Error>

Wraps value with radix radix.

§Errors
  • InvalidArgument: radix is outside 2..=36.
Source

pub fn with_radix(value: ExactNum, radix: Radix) -> RadixFloat

Wraps value with radix without validating the radix (for const radix constants).

Source

pub fn value(&self) -> &ExactNum

Returns the numeric value.

Source

pub const fn radix(&self) -> Radix

Returns the associated radix.

Source

pub fn into_inner(self) -> ExactNum

Consumes self and returns the inner ExactNum.

Source

pub fn parse( s: &str, radix: Radix, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> Result<RadixFloat, Error>

Parses s in radix.

Source

pub fn format(&self, rm: RoundingMode, cc: &mut Consts) -> Result<String, Error>

Formats using the associated radix.

Methods from Deref<Target = ExactNum>§

Source

pub fn to_inline_bytes(&self) -> Result<InlineBinaryBuffer, Error>

Encode an inlined value into a stack buffer.

Specials always succeed. A finite mantissa wider than BINARY_INLINE_MANT_BITS returns Error::MemoryAllocation.

Source

pub fn write_inline_bytes(&self, dest: &mut [u8]) -> Result<usize, Error>

Write the 16-byte inline record into dest.

Returns Error::InvalidArgument if dest is shorter than BINARY_INLINE_LEN. Wider finite mantissas return Error::MemoryAllocation.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, Error>

Encode self (inline 16 bytes, or a heap record if the mantissa is wider).

Source

pub fn write_bytes(&self, dest: &mut [u8]) -> Result<usize, Error>

Write the compact record into dest without allocating.

Source

pub fn normal_pdf( &self, mu: &ExactNum, sigma: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Standard-form normal density (\varphi(x;\mu,\sigma)=\exp(-(x-\mu)^2/(2\sigma^2))/(\sigma\sqrt{2\pi})).

sigma ≤ 0 or a non-finite parameter is NaN.

§Precision
  • Algorithm: exp / sqrt / π at p + WORD_BIT_SIZE, then one rounding to p.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no (composite of existing leaves).
Source

pub fn normal_cdf( &self, mu: &ExactNum, sigma: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Normal CDF (\Phi(x;\mu,\sigma)=(1+\mathrm{erf}((x-\mu)/(\sigma\sqrt{2})))/2).

sigma ≤ 0 is NaN.

§Precision
  • Algorithm: existing erf at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no (composite of erf).
Source

pub fn gamma_pdf( &self, alpha: &ExactNum, beta: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Gamma density on the scale parameterization (x^{\alpha-1}e^{-x/\beta}/(\beta^\alpha\Gamma(\alpha))).

Requires x ≥ 0, alpha > 0, beta > 0.

§Precision
  • Algorithm: pow / exp / gamma at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn beta_pdf( &self, alpha: &ExactNum, beta: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Beta density (x^{\alpha-1}(1-x)^{\beta-1}/B(\alpha,\beta)) with (B(\alpha,\beta)=\Gamma(\alpha)\Gamma(\beta)/\Gamma(\alpha+\beta)).

Requires x ∈ [0, 1], alpha > 0, beta > 0.

§Precision
  • Algorithm: pow / gamma at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn poisson_pmf( &self, lambda: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Poisson PMF (\lambda^k e^{-\lambda}/k!) for a non-negative integer self (= k).

§Precision
  • Algorithm: pow / exp / (\Gamma(k+1)) at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn binomial_pmf( &self, n: &ExactNum, prob: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Binomial PMF (\binom{n}{k} \mathrm{prob}^k (1-\mathrm{prob})^{n-k}).

self is (k). Requires non-negative integers k ≤ n and prob ∈ [0, 1].

§Precision
  • Algorithm: multiplicative binomial coefficient, then pow.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn chi_squared_cdf( &self, k: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Chi-squared CDF (P(k/2, x/2)=\gamma(k/2, x/2)/\Gamma(k/2)).

self is (x). Requires x ≥ 0 and k > 0.

§Precision
  • Algorithm: lower gammainc over gamma at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn student_t_pdf( &self, nu: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Student-(t) density via (\Gamma): (\Gamma((\nu+1)/2)/(\sqrt{\nu\pi},\Gamma(\nu/2)),(1+x^2/\nu)^{-(\nu+1)/2}).

self is (x). Requires nu > 0.

§Precision
  • Algorithm: gamma / pow / sqrt at p + WORD_BIT_SIZE.
  • Bound: working precision p + WORD_BIT_SIZE.
  • MPFR oracle: no.
Source

pub fn is_inf_pos(&self) -> bool

Returns true if self is positive infinity.

Source

pub fn is_inf_neg(&self) -> bool

Returns true if self is negative infinity.

Source

pub fn is_inf(&self) -> bool

Returns true if self is infinite.

Source

pub fn is_nan(&self) -> bool

Return true if self is not a number.

Source

pub fn is_int(&self) -> bool

Return true if self is an integer number.

Source

pub fn err(&self) -> Option<Error>

Returns the associated with NaN error, if any.

Source

pub fn add(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Adds d2 to self and returns the result of the operation with precision p rounded according to rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn add_full_prec(&self, d2: &ExactNum) -> ExactNum

Adds d2 to self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer addition.

Source

pub fn sub(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Subtracts d2 from self and returns the result of the operation with precision p rounded according to rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn sub_full_prec(&self, d2: &ExactNum) -> ExactNum

Subtracts d2 from self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer subtraction.

Source

pub fn mul(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Multiplies d2 by self and returns the result of the operation with precision p rounded according to rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn mul_full_prec(&self, d2: &ExactNum) -> ExactNum

Multiplies d2 by self and returns the result of the operation. The resulting precision is equal to the full precision of the result. This operation can be used to emulate integer multiplication.

Source

pub fn fma( &self, b: &ExactNum, c: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum

Computes self * b + c with precision p, rounded once with rm.

Unlike mul followed by add, the product is not rounded to p before the addition.

Source

pub fn two_sum( &self, b: &ExactNum, p: usize, rm: RoundingMode, ) -> (ExactNum, ExactNum)

Knuth–Dekker two-sum: (hi, lo) with hi rounded to p bits using rm and hi + lo equal to the exact sum of finite operands (via add_full_prec). Unlike a hardware-float Dekker two-sum, this takes (p, rm) because the high part is an ExactNum at a chosen precision, not an implicit machine word.

Inf / NaN: hi is self.add(b, p, rm); lo is zero (or NaN if hi is NaN). Reconstruct with hi.add(&lo, p, rm) (not add_full_prec, which uses internal precision 0).

Source

pub fn two_product( &self, b: &ExactNum, p: usize, rm: RoundingMode, ) -> (ExactNum, ExactNum)

Two-product: (hi, lo) with hi rounded to p bits using rm and hi + lo equal to the exact product of finite operands (via mul_full_prec).

Source

pub fn mul_add( &self, b: &ExactNum, c: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum

Alias of Self::fma.

Source

pub fn div(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Divides self by d2 and returns the result of the operation with precision p rounded according to rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn rem(&self, d2: &ExactNum) -> ExactNum

Returns the remainder of division of |self| by |d2|. The sign of the result is set to the sign of self.

Source

pub fn cmp(&self, d2: &ExactNum) -> Option<i128>

Compares self to d2. Returns positive if self > d2, negative if self < d2, zero if self == d2, None if self or d2 is NaN.

Source

pub fn abs_cmp(&self, d2: &ExactNum) -> Option<i128>

Compares the absolute value of self to the absolute value of d2. Returns positive if |self| is greater than |d2|, negative if |self| is smaller than |d2|, 0 if |self| equals to |d2|, None if self or d2 is NaN.

Source

pub fn inv_sign(&mut self)

Reverses the sign of self.

Source

pub fn pow( &self, n: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Compute the power of self to the n with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn powi(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Compute the power of self to the integer n with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn powsi(&self, n: isize, p: usize, rm: RoundingMode) -> ExactNum

Compute the power of self to the signed integer n with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. Negative n is a reciprocal of the corresponding positive power. The function returns NaN if the precision p is incorrect, or Inf if self is zero and n is negative.

Source

pub fn log( &self, n: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Computes the logarithm base n of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn is_positive(&self) -> bool

Returns true if self is positive. The function returns false if self is NaN.

Source

pub fn is_negative(&self) -> bool

Returns true if self is negative. The function returns false if self is NaN.

Source

pub fn is_subnormal(&self) -> bool

Returns true if self is subnormal. A number is subnormal if the most significant bit of the mantissa is not equal to 1.

Source

pub fn is_zero(&self) -> bool

Returns true if self is zero.

Source

pub fn clamp(&self, min: &ExactNum, max: &ExactNum) -> ExactNum

Restricts the value of self to an interval determined by the values of min and max. The function returns max if self is greater than max, min if self is less than min, and self otherwise. If either argument is NaN or min is greater than max, the function returns NaN.

Source

pub fn max(&self, d1: &ExactNum) -> ExactNum

Returns the value of d1 if d1 is greater than self, or the value of self otherwise. If either argument is NaN, the function returns NaN.

Source

pub fn min(&self, d1: &ExactNum) -> ExactNum

Returns value of d1 if d1 is less than self, or the value of self otherwise. If either argument is NaN, the function returns NaN.

Source

pub fn signum(&self) -> ExactNum

Returns a ExactNum with the value -1 if self is negative, 1 if self is positive, zero otherwise. The function returns NaN If self is NaN.

Source

pub fn format( &self, rdx: Radix, rm: RoundingMode, cc: &mut Consts, ) -> Result<String, Error>

Formats the number using radix rdx and rounding mode rm. Note, since hexadecimal digits include the character “e”, the exponent part is separated from the mantissa by “_”. For example, a number with mantissa 123abcdef and exponent 123 would be formatted as 123abcdef_e+123.

§Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
Source

pub fn classify(&self) -> FpCategory

Returns category of self.

Source

pub fn atan(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the arctangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn atan2( &self, x: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Computes atan2(self, x) with precision p (quadrant-aware arctangent of self / x). The result is rounded using the rounding mode rm. This function requires constants cache cc. Precision is rounded upwards to the word size.

Source

pub fn hypot(&self, other: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Computes sqrt(self² + other²) with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. hypot(±Inf, y) and hypot(x, ±Inf) are +Inf, including when the other argument is NaN.

Source

pub fn log1p(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes ln(1 + self) with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc. Returns -Inf for self == -1, and NaN if self < -1.

Source

pub fn expm1(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes exp(self) - 1 with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc.

Source

pub fn tanh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic tangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn exponent(&self) -> Option<i32>

Returns the exponent of self, or None if self is Inf or NaN.

Source

pub fn precision(&self) -> Option<usize>

Returns the number of significant bits used in the mantissa, or None if self is Inf or NaN. Normal numbers use all bits of the mantissa. Subnormal numbers use fewer bits than the mantissa can hold.

Source

pub fn neg(&self) -> ExactNum

Returns a copy of the number with the sign reversed.

Source

pub fn as_raw_parts(&self) -> Option<(&[u64], usize, Sign, i32, bool)>

Decomposes self into raw parts. The function returns a reference to a slice of words representing mantissa, numbers of significant bits in the mantissa, sign, exponent, and a bool value which specify whether the number is inexact.

Source

pub fn sign(&self) -> Option<Sign>

Returns the sign of self, or None if self is NaN.

Source

pub fn set_exponent(&mut self, e: i32)

Sets the exponent of self. Note that if self is subnormal, the exponent may not change, but the mantissa will shift instead. e will be clamped to the range from EXPONENT_MIN to EXPONENT_MAX if it’s outside of the range. See example below.

§Examples
// construct a subnormal value.
let mut n = ExactNum::min_positive(128);

assert_eq!(n.exponent(), Some(EXPONENT_MIN));
assert_eq!(n.precision(), Some(1));

// increase exponent.
let n_exp = n.exponent().expect("n is not NaN");
n.set_exponent(n_exp + 1);

// the outcome for subnormal number.
assert_eq!(n.exponent(), Some(EXPONENT_MIN));
assert_eq!(n.precision(), Some(2));
Source

pub fn mantissa_max_bit_len(&self) -> Option<usize>

Returns the maximum mantissa length of self in bits regardless of whether self is normal or subnormal.

Source

pub fn is_inline(&self) -> bool

True when a finite value stores its mantissa on the stack (at most crate::INLINE_WORDS limbs). Inf and NaN return false.

Source

pub fn set_precision(&mut self, p: usize, rm: RoundingMode) -> Result<(), Error>

Sets the precision of self to p. If the new precision is smaller than the existing one, the number is rounded using specified rounding mode rm.

§Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • InvalidArgument: the precision is incorrect.
Source

pub fn reciprocal(&self, p: usize, rm: RoundingMode) -> ExactNum

Computes the reciprocal of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn set_sign(&mut self, s: Sign)

Sets the sign of self.

Source

pub fn mantissa_digits(&self) -> Option<&[u64]>

Returns the raw mantissa words of a number.

Source

pub fn convert_to_radix( &self, rdx: Radix, rm: RoundingMode, cc: &mut Consts, ) -> Result<(Sign, Vec<u8>, i32), Error>

Converts self to radix rdx using rounding mode rm. The function returns sign, mantissa digits in radix rdx, and exponent such that the converted number can be represented as mantissa digits * rdx ^ exponent. The first element in the mantissa is the most significant digit.

§Examples

let mut cc = Consts::new().expect("Constants cache initialized.");
let n = ExactNum::parse("123.45678", Radix::Dec, 64, RoundingMode::None, &mut cc);
let (s, m, _e) = n.convert_to_radix(Radix::Dec, RoundingMode::None, &mut cc).expect("Conversion failed");
assert_eq!(s, Sign::Pos);
assert!(!m.is_empty());
§Errors
  • MemoryAllocation: failed to allocate memory for mantissa.
  • ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
  • InvalidArgument: self is Inf or NaN.
Source

pub fn inexact(&self) -> bool

Returns true if self is inexact. The function returns false if self is Inf or NaN.

Source

pub fn set_inexact(&mut self, inexact: bool)

Marks self as inexact if inexact is true, or exact otherwise. The function has no effect if self is Inf or NaN.

Source

pub fn try_set_precision( &mut self, p: usize, rm: RoundingMode, s: usize, ) -> bool

Try to round and then set the precision to p, given self has s correct digits in mantissa. The function returns true if rounding succeeded, or if self is Inf or NaN. If the fuction returns false, self is still modified, and should be discarded. In case of an error, self will be set to NaN with an associated error. If the precision p is incorrect self will be set to NaN.

Source

pub fn frexp(&self) -> (ExactNum, i32)

Split self = m · 2^e with m in [0.5, 1) (zeros return (0, 0); Inf/NaN return (self, 0)).

Source

pub fn ldexp(&self, n: i32, p: usize, rm: RoundingMode) -> ExactNum

self · 2^n. Alias of Self::scalb.

Source

pub fn scalb(&self, n: i32, p: usize, rm: RoundingMode) -> ExactNum

self · 2^n (IEEE scalbn).

Source

pub fn logb(&self, p: usize, rm: RoundingMode) -> ExactNum

floor(log2(|self|)) as a float. Zero becomes -Inf; Inf/NaN unchanged in kind.

Source

pub fn ilogb(&self) -> Option<i32>

Integer floor(log2(|self|)). None for zero, Inf, or NaN.

Source

pub fn abs(&self) -> ExactNum

Returns the absolute value of self.

Source

pub fn copysign(&self, sign: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum

Returns a value with the magnitude of self and the sign of sign.

Source

pub fn next_after( &self, toward: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum

Returns the next representable value from self toward toward at precision p.

Source

pub fn int(&self) -> ExactNum

Returns the integer part of self.

Source

pub fn fract(&self) -> ExactNum

Returns the fractional part of self.

Source

pub fn ceil(&self) -> ExactNum

Returns the smallest integer greater than or equal to self.

Source

pub fn floor(&self) -> ExactNum

Returns the largest integer less than or equal to self.

Source

pub fn round(&self, n: usize, rm: RoundingMode) -> ExactNum

Returns the rounded number with n binary positions in the fractional part of the number using rounding mode rm.

Source

pub fn sqrt(&self, p: usize, rm: RoundingMode) -> ExactNum

Computes the square root of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn cbrt(&self, p: usize, rm: RoundingMode) -> ExactNum

Computes the cube root of a number with precision p. The result is rounded using the rounding mode rm. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn nth_root(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Computes the n-th root of self with precision p. n = 2 and n = 3 delegate to sqrt and cbrt.

Source

pub fn ln(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the natural logarithm of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn log2(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the logarithm base 2 of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn log10(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the logarithm base 10 of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn exp(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes e to the power of self with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn exp2(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes 2 to the power of self with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn exp10(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes 10 to the power of self with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn rem_pi(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Reduces self modulo into the interval (-2π, 2π) using precision p and rounding mode rm. This function requires constants cache cc for computing the result.

Source

pub fn sin(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the sine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn cos(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the cosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn sin_cos( &self, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> (ExactNum, ExactNum)

Computes (sin(self), cos(self)) with precision p using a shared argument reduction.

Source

pub fn tan(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the tangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn asin(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the arcsine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn acos(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the arccosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn sinh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic sine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn cosh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic cosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn sinh_cosh( &self, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> (ExactNum, ExactNum)

Computes (sinh(self), cosh(self)) with precision p using a single exp(|x|) evaluation.

Source

pub fn erf(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Error function erf(self) with precision p.

§Precision
  • Algorithm: Taylor series when |x|.exponent() ≤ 2; complementary asymptotic otherwise. Saturates to ±1 when 2|e| > p+4.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR on |x| ≲ 4.
  • Thresholds: exponent cut ≤ 2 (not a named constant).
  • MPFR oracle: yes, |x| ≲ 4 under mpfr-tests. Complex erf on the real axis uses the same oracle; GNU MPC has no mpc_erf.
Source

pub fn erfc(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Complementary error function erfc(self) = 1 - erf(self) with precision p.

§Precision
  • Algorithm: 1 - erf at extra working precision (same series / asymptotic as erf).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR on |x| ≲ 4.
  • MPFR oracle: yes, |x| ≲ 4 under mpfr-tests.
Source

pub fn gamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Gamma function Γ(self) with precision p. Poles at non-positive integers yield NaN (or +Inf at 0).

§Precision
  • Algorithm: Stirling series for ln Γ then exp; reflection across the negative axis. Integer factorials for small positive integers.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR on the oracle domain.
  • MPFR oracle: yes, under mpfr-tests.
Source

pub fn ln_gamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

ln Γ(self) for positive self with precision p.

§Precision
  • Algorithm: Stirling series (Bernoulli) at working precision p + WORD_BIT_SIZE.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR on the oracle domain.
  • MPFR oracle: yes, under mpfr-tests.
Source

pub fn digamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Digamma ψ(self). Poles at non-positive integers. Reflection for z < 0.

§Precision
  • Algorithm: recurrence to a large argument, then Bernoulli series; reflection for z < 0.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR digamma on z > 0.
  • MPFR oracle: yes, z > 0 under mpfr-tests.
Source

pub fn gammainc( &self, x: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Lower incomplete gamma γ(self, x) for self > 0, x ≥ 0.

§Precision
  • Algorithm: power series in x at working precision; +∞ in x returns Γ(self).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: identity γ(s,x)=Γ(s)−Γ(s,x); upper uses mpfr_gamma_inc.
Source

pub fn gammainc_upper( &self, x: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Upper incomplete gamma Γ(self, x) for self > 0, x ≥ 0.

§Precision
  • Algorithm: Γ(self) - γ(self, x) at working precision; +∞ in x returns 0.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: yes, mpfr_gamma_inc under mpfr-tests.
Source

pub fn ei(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Exponential integral Ei(self) (principal value for self < 0). 0 is a pole.

§Precision
  • Algorithm: power series for moderate |x|; factorial asymptotic when |x| is large (exponent() > 6 and |x| ≳ 0.7 p).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: yes, mpfr_eint under mpfr-tests.
Source

pub fn si(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Sine integral Si(self). +∞ → π/2, −∞ → −π/2.

§Precision
  • Algorithm: series, or auxiliary f,g asymptotic on the same cut as Ei.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (Si odd, Si(0)=0, Si(+∞)=π/2).
Source

pub fn ci(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Cosine integral Ci(self) for self > 0.

§Precision
  • Algorithm: series, or auxiliary f,g asymptotic (same |x| cut as Ei). Near-zero is a pole.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (identity / series golds; GNU MPFR has no Si/Ci).
Source

pub fn li(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Logarithmic integral li(self) = Ei(ln self) for self > 0, self ≠ 1.

§Precision
  • Algorithm: Ei(ln self) at extra working precision (inherits Ei series / asymptotic).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (li(e)=Ei(1) identity).
Source

pub fn fresnel_s(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Fresnel sine integral S(self). ±∞ → ±1/2.

§Precision
  • Algorithm: series, or auxiliary f,g when |x|.exponent() ≥ 8 (or 3 x² > p).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (S odd, S(0)=0, S(+∞)=1/2).
Source

pub fn fresnel_c(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Fresnel cosine integral C(self). ±∞ → ±1/2.

§Precision
  • Algorithm: same series / auxiliary f,g split as Self::fresnel_s.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (same identities as Self::fresnel_s).
Source

pub fn ai(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Airy (\mathrm{Ai}(\mathrm{self})). (+\infty\to 0); (-\infty) has no limit → NaN.

§Precision
  • Algorithm: power series for |x| < AIRY_SERIES_THRESHOLD (8); asymptotic otherwise.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: yes, mpfr_ai under mpfr-tests.
Source

pub fn bi(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Airy (\mathrm{Bi}(\mathrm{self})). (+\infty\to+\infty); (-\infty) has no limit → NaN.

§Precision
  • Algorithm: same AIRY_SERIES_THRESHOLD = 8 split as Self::ai.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (Ai Bi' − Ai' Bi = 1/π; GNU MPFR has no Bi).
Source

pub fn ai_prime(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

(\mathrm{Ai}’(\mathrm{self})). (+\infty\to 0); (-\infty) → NaN.

§Precision
  • Algorithm: differentiated series / asymptotic; AIRY_SERIES_THRESHOLD = 8.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn bi_prime(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

(\mathrm{Bi}’(\mathrm{self})). (+\infty\to+\infty); (-\infty) → NaN.

§Precision
  • Algorithm: differentiated series / asymptotic; AIRY_SERIES_THRESHOLD = 8.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn bessel_j( &self, n: usize, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Bessel function of the first kind J_n(self) for integer order n.

§Precision
  • Algorithm: power series; Miller recurrence for large n (n ≤ 1024).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY). 1 ULP vs MPFR jn for n = 0,1,2.
  • MPFR oracle: yes, n = 0,1,2 under mpfr-tests.
Source

pub fn bessel_j_nu( &self, nu: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

(J_ν(\mathrm{self})) for real order nu.

§Precision
  • Algorithm: series in x; integer ν delegates to Self::bessel_j.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (identity golds).
Source

pub fn bessel_y( &self, nu: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

(Y_ν(\mathrm{self})) for self > 0.

§Precision
  • Algorithm: Wronskian / series from (J_ν); cut on ((-\infty, 0]).
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: yes, mpfr_yn for n = 0,1 under mpfr-tests.
Source

pub fn bessel_i( &self, nu: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

(I_ν(\mathrm{self})).

§Precision
  • Algorithm: series; (I_ν(z) = i^{-ν} J_ν(iz)) for the complex path.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn bessel_k( &self, nu: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

(K_ν(\mathrm{self})) for self > 0. (K_{-ν}=K_ν).

§Precision
  • Algorithm: series / Temme; large-|x| asymptotic k_asymptotic.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn elliptic_k( &self, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Complete elliptic K(self). Parameter m = k². m = 1 is +∞; m > 1 uses the reciprocal-modulus transform.

§Precision
  • Algorithm: Carlson R_F duplication; cap CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no (identity golds; GNU MPFR has no Carlson K).
Source

pub fn elliptic_e_complete( &self, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Complete elliptic E(self) for self ≤ 1. E(1) = 1.

§Precision
  • Algorithm: Carlson R_F / R_D; CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn elliptic_f( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Incomplete F(self | m) for |self| ≤ 1. self = sin φ, m = k².

§Precision
  • Algorithm: Carlson R_F; CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn elliptic_e( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Incomplete E(self | m) for |self| ≤ 1.

§Precision
  • Algorithm: Carlson R_F / R_D; CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn elliptic_pi_complete( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Complete Π(self, m) for self < 1, m < 1.

§Precision
  • Algorithm: Carlson R_J; CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn elliptic_pi( &self, x: &ExactNum, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Incomplete Π(self; x | m).

§Precision
  • Algorithm: Carlson R_J; CARLSON_DUPE_MAX = 128.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn legendre_p(&self, n: u32, p: usize, rm: RoundingMode) -> ExactNum

Legendre (P_n(\mathrm{self})) for integer n.

§Precision
  • Algorithm: three-term recurrence at p + O(n) bits. Cap ORTHOPOLY_N_MAX.
  • Bound: working-precision recurrence (not a Ziv leaf).
  • MPFR oracle: no.
Source

pub fn assoc_legendre_p( &self, n: u32, m: i32, p: usize, rm: RoundingMode, ) -> ExactNum

Associated (P_n^m(\mathrm{self})) (Condon–Shortley).

§Precision
  • Algorithm: recurrence from (P_n); Condon–Shortley phase.
  • Bound: working-precision recurrence (not a Ziv leaf).
  • MPFR oracle: no.
Source

pub fn hypergeom_2f1( &self, b: &ExactNum, c: &ExactNum, z: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Gaussian ({}_2F_1(\mathrm{self}, b; c; z)).

§Precision
  • Algorithm: series for |z| < 1; Gauss at z = 1; Pfaff / continuation. Cap HYPERGEOM_TERM_MAX = 10_000.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY) when the series converges.
  • MPFR oracle: no.
Source

pub fn betainc( &self, b: &ExactNum, x: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum

Regularized incomplete beta (I_x(a=\mathrm{self}, b)).

§Precision
  • Algorithm: series / continued fraction in x ∈ [0, 1] for a > 0, b > 0.
  • Bound: Ziv correct-rounding (MAX_PREC_RETRY).
  • MPFR oracle: no.
Source

pub fn asinh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic arcsine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn acosh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic arccosine of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn atanh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum

Computes the hyperbolic arctangent of a number with precision p. The result is rounded using the rounding mode rm. This function requires constants cache cc for computing the result. Precision is rounded upwards to the word size. The function returns NaN if the precision p is incorrect.

Source

pub fn hermite_he(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Probabilist’s Hermite polynomial He_n(self).

He_0 = 1, He_1 = x, He_{n+1} = x He_n − n He_{n−1}. n > ORTHOPOLY_N_MAX or non-finite self is NaN.

Source

pub fn hermite_h(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Physicist’s Hermite polynomial H_n(self).

H_0 = 1, H_1 = 2x, H_{n+1} = 2x H_n − 2n H_{n−1}. n > ORTHOPOLY_N_MAX or non-finite self is NaN.

Source

pub fn laguerre(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Laguerre polynomial L_n(self).

L_0 = 1, L_1 = 1 − x, L_{n+1} = ((2n+1−x) L_n − n L_{n−1}) / (n+1). n > ORTHOPOLY_N_MAX or non-finite self is NaN.

Source

pub fn gen_laguerre( &self, n: usize, alpha: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum

Generalized Laguerre L_n^{(α)}(self).

L_0^{(α)} = 1, L_1^{(α)} = 1+α−x, L_{n+1}^{(α)} = (((2n+1+α−x) L_n − (n+α) L_{n−1}) / (n+1). n > ORTHOPOLY_N_MAX or a non-finite argument is NaN.

Source

pub fn chebyshev_t(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Chebyshev polynomial of the first kind T_n(self).

T_0 = 1, T_1 = x, T_{n+1} = 2x T_n − T_{n−1}. n > ORTHOPOLY_N_MAX or non-finite self is NaN.

Source

pub fn chebyshev_u(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum

Chebyshev polynomial of the second kind U_n(self).

U_0 = 1, U_1 = 2x, U_{n+1} = 2x U_n − U_{n−1}. n > ORTHOPOLY_N_MAX or non-finite self is NaN.

Source

pub fn gegenbauer( &self, n: usize, lambda: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum

Gegenbauer (ultraspherical) polynomial C_n^{(λ)}(self).

C_0 = 1, C_1 = 2λ x, C_{n+1} = (2(n+λ) x C_n − (n+2λ−1) C_{n−1}) / (n+1). Standard C_n^{(λ)}: C_2^{(1)} = 4x² − 1 = U_2, and C_n^{(1/2)} = P_n (Legendre). n > ORTHOPOLY_N_MAX or a non-finite argument is NaN.

Source

pub fn format_exact(&self, rdx: Radix) -> Option<String>

Minimum digits in rdx that recover self exactly when the value is a terminating expansion in that radix.

Trait Implementations§

Source§

impl Clone for RadixFloat

Source§

fn clone(&self) -> RadixFloat

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RadixFloat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Deref for RadixFloat

Source§

type Target = ExactNum

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ExactNum

Dereferences the value.
Source§

impl DerefMut for RadixFloat

Source§

fn deref_mut(&mut self) -> &mut ExactNum

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.