pub struct ExactNum { /* private fields */ }Expand description
A floating point number of arbitrary precision.
Implementations§
Source§impl ExactNum
impl ExactNum
Sourcepub fn to_inline_bytes(&self) -> Result<InlineBinaryBuffer, Error>
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.
Sourcepub fn write_inline_bytes(&self, dest: &mut [u8]) -> Result<usize, Error>
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.
Sourcepub fn from_inline_bytes(bytes: &[u8; 16]) -> Result<ExactNum, Error>
pub fn from_inline_bytes(bytes: &[u8; 16]) -> Result<ExactNum, Error>
Decode a 16-byte inline record.
Sourcepub fn to_bytes(&self) -> Result<Vec<u8>, Error>
pub fn to_bytes(&self) -> Result<Vec<u8>, Error>
Encode self (inline 16 bytes, or a heap record if the mantissa is wider).
Sourcepub fn write_bytes(&self, dest: &mut [u8]) -> Result<usize, Error>
pub fn write_bytes(&self, dest: &mut [u8]) -> Result<usize, Error>
Write the compact record into dest without allocating.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<ExactNum, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<ExactNum, Error>
Decode a compact record. Extra trailing bytes are Error::InvalidArgument.
Source§impl ExactNum
impl ExactNum
Sourcepub fn normal_pdf(
&self,
mu: &ExactNum,
sigma: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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/πatp + WORD_BIT_SIZE, then one rounding top. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no (composite of existing leaves).
Sourcepub fn normal_cdf(
&self,
mu: &ExactNum,
sigma: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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
erfatp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no (composite of
erf).
Sourcepub fn gamma_pdf(
&self,
alpha: &ExactNum,
beta: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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/gammaatp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no.
Sourcepub fn beta_pdf(
&self,
alpha: &ExactNum,
beta: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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/gammaatp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no.
Sourcepub fn poisson_pmf(
&self,
lambda: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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)) atp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no.
Sourcepub fn binomial_pmf(
&self,
n: &ExactNum,
prob: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn chi_squared_cdf(
&self,
k: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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
gammaincovergammaatp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no.
Sourcepub fn student_t_pdf(
&self,
nu: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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/sqrtatp + WORD_BIT_SIZE. - Bound: working precision
p + WORD_BIT_SIZE. - MPFR oracle: no.
Source§impl ExactNum
impl ExactNum
Sourcepub fn new(p: usize) -> ExactNum
pub fn new(p: usize) -> ExactNum
Returns a new number with value of 0 and precision of p bits. Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn nan(err: Option<Error>) -> ExactNum
pub fn nan(err: Option<Error>) -> ExactNum
Constructs not-a-number with an associated error err.
Sourcepub fn is_inf_pos(&self) -> bool
pub fn is_inf_pos(&self) -> bool
Returns true if self is positive infinity.
Sourcepub fn is_inf_neg(&self) -> bool
pub fn is_inf_neg(&self) -> bool
Returns true if self is negative infinity.
Sourcepub fn add(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn add_full_prec(&self, d2: &ExactNum) -> ExactNum
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.
Sourcepub fn sub(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn sub_full_prec(&self, d2: &ExactNum) -> ExactNum
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.
Sourcepub fn mul(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn mul_full_prec(&self, d2: &ExactNum) -> ExactNum
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.
Sourcepub fn fma(
&self,
b: &ExactNum,
c: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
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.
Sourcepub fn two_sum(
&self,
b: &ExactNum,
p: usize,
rm: RoundingMode,
) -> (ExactNum, ExactNum)
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).
Sourcepub fn two_product(
&self,
b: &ExactNum,
p: usize,
rm: RoundingMode,
) -> (ExactNum, ExactNum)
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).
Sourcepub fn fused_sum(xs: &[ExactNum], p: usize, rm: RoundingMode) -> ExactNum
pub fn fused_sum(xs: &[ExactNum], p: usize, rm: RoundingMode) -> ExactNum
Sum xs at extra working precision and round once to p bits.
Sourcepub fn fused_dot(
xs: &[ExactNum],
ys: &[ExactNum],
p: usize,
rm: RoundingMode,
) -> ExactNum
pub fn fused_dot( xs: &[ExactNum], ys: &[ExactNum], p: usize, rm: RoundingMode, ) -> ExactNum
Dot product of equal-length slices: extra-precision ∑ xs[i]*ys[i], then one round to p.
Length mismatch yields NaN (InvalidArgument).
Sourcepub fn polyval(
coeffs: &[ExactNum],
x: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
pub fn polyval( coeffs: &[ExactNum], x: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum
Horner evaluation a₀ + x(a₁ + x(a₂ + …)) with fused multiply-add at extra working precision,
then one round to p. coeffs[0] is the constant term (lowest degree first).
Empty coeffs yields zero.
Sourcepub fn mul_add(
&self,
b: &ExactNum,
c: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
pub fn mul_add( &self, b: &ExactNum, c: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum
Alias of Self::fma.
Sourcepub fn div(&self, d2: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn rem(&self, d2: &ExactNum) -> ExactNum
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.
Sourcepub fn cmp(&self, d2: &ExactNum) -> Option<i128>
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.
Sourcepub fn abs_cmp(&self, d2: &ExactNum) -> Option<i128>
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.
Sourcepub fn pow(
&self,
n: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn powi(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn powsi(&self, n: isize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn log(
&self,
n: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if self is positive.
The function returns false if self is NaN.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if self is negative.
The function returns false if self is NaN.
Sourcepub fn is_subnormal(&self) -> bool
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.
Sourcepub fn clamp(&self, min: &ExactNum, max: &ExactNum) -> ExactNum
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.
Sourcepub fn max(&self, d1: &ExactNum) -> ExactNum
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.
Sourcepub fn min(&self, d1: &ExactNum) -> ExactNum
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.
Sourcepub fn signum(&self) -> ExactNum
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.
Sourcepub fn parse(
s: &str,
rdx: Radix,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn parse( s: &str, rdx: Radix, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
Parses a number from the string s.
The function expects s to be a number in scientific format in radix rdx, or +-Inf, or NaN.
if p equals to usize::MAX then the precision of the resulting number is determined automatically from the input.
§Examples
let mut cc = Consts::new().expect("Constants cache initialized.");
let n = ExactNum::parse("0.0", Radix::Bin, 64, RoundingMode::ToEven, &mut cc);
assert!(n.is_zero());
let n = ExactNum::parse("-Inf", Radix::Hex, 1, RoundingMode::None, &mut cc);
assert!(n.is_inf_neg());
let n = ExactNum::parse("NaN", Radix::Oct, 2, RoundingMode::None, &mut cc);
assert!(n.is_nan());Sourcepub fn format(
&self,
rdx: Radix,
rm: RoundingMode,
cc: &mut Consts,
) -> Result<String, Error>
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.
Sourcepub fn with_radix(self, radix: Radix) -> RadixFloat
pub fn with_radix(self, radix: Radix) -> RadixFloat
Wraps self in a crate::RadixFloat tagged with radix for parse/format.
Sourcepub fn classify(&self) -> FpCategory
pub fn classify(&self) -> FpCategory
Returns category of self.
Sourcepub fn atan(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn atan2(
&self,
x: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn hypot(&self, other: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn log1p(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn expm1(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn tanh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn exponent(&self) -> Option<i32>
pub fn exponent(&self) -> Option<i32>
Returns the exponent of self, or None if self is Inf or NaN.
Sourcepub fn precision(&self) -> Option<usize>
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.
Sourcepub fn max_value(p: usize) -> ExactNum
pub fn max_value(p: usize) -> ExactNum
Returns the maximum value for the specified precision p: all bits of the mantissa are set to 1,
the exponent has the maximum possible value, and the sign is positive.
Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn min_value(p: usize) -> ExactNum
pub fn min_value(p: usize) -> ExactNum
Returns the minimum value for the specified precision p: all bits of the mantissa are set to 1, the exponent has the maximum possible value, and the sign is negative. Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn min_positive(p: usize) -> ExactNum
pub fn min_positive(p: usize) -> ExactNum
Returns the minimum positive subnormal value for the specified precision p:
only the least significant bit of the mantissa is set to 1, the exponent has
the minimum possible value, and the sign is positive.
Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn min_positive_normal(p: usize) -> ExactNum
pub fn min_positive_normal(p: usize) -> ExactNum
Returns the minimum positive normal value for the specified precision p:
only the most significant bit of the mantissa is set to 1, the exponent has
the minimum possible value, and the sign is positive.
Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn from_word(d: u64, p: usize) -> ExactNum
pub fn from_word(d: u64, p: usize) -> ExactNum
Returns a new number with value d and the precision p. Precision is rounded upwards to the word size.
The function returns NaN if the precision p is incorrect.
Sourcepub fn as_raw_parts(&self) -> Option<(&[u64], usize, Sign, i32, bool)>
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.
Sourcepub fn from_raw_parts(
m: &[u64],
n: usize,
s: Sign,
e: i32,
inexact: bool,
) -> ExactNum
pub fn from_raw_parts( m: &[u64], n: usize, s: Sign, e: i32, inexact: bool, ) -> ExactNum
Constructs a number from the raw parts:
mis the mantisaa.nis the number of significant bits in mantissa.sis the sign.eis the exponent.inexactspecify whether number is inexact.
This function returns NaN in the following situations:
nis larger than the number of bits inm.nis smaller than the number of bits inm, butmdoes not represent corresponding subnormal number mantissa.nis smaller than the number of bits inm, buteis not the minimum possible exponent.nor the size ofmis too large (larger than isize::MAX / 2 + EXPONENT_MIN).eis less than EXPONENT_MIN or greater than EXPONENT_MAX.
Sourcepub fn from_words(m: &[u64], s: Sign, e: i32) -> ExactNum
pub fn from_words(m: &[u64], s: Sign, e: i32) -> ExactNum
Constructs a number from the slice of words:
mis the mantissa.sis the sign.eis the exponent.
The function returns NaN if e is less than EXPONENT_MIN or greater than EXPONENT_MAX.
Sourcepub fn set_exponent(&mut self, e: i32)
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));Sourcepub fn mantissa_max_bit_len(&self) -> Option<usize>
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.
Sourcepub fn is_inline(&self) -> bool
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.
Sourcepub fn set_precision(&mut self, p: usize, rm: RoundingMode) -> Result<(), Error>
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.
Sourcepub fn reciprocal(&self, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn mantissa_digits(&self) -> Option<&[u64]>
pub fn mantissa_digits(&self) -> Option<&[u64]>
Returns the raw mantissa words of a number.
Sourcepub fn convert_from_radix(
sign: Sign,
digits: &[u8],
e: i32,
rdx: Radix,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn convert_from_radix( sign: Sign, digits: &[u8], e: i32, rdx: Radix, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
Converts an array of digits in radix rdx to ExactNum with precision p.
digits represents mantissa and is interpreted as a number smaller than 1 and greater or equal to 1/rdx.
The first element in digits is the most significant digit.
e is the exponent part of the number, such that the number can be represented as digits * rdx ^ e.
Precision is rounded upwards to the word size.
if p equals usize::MAX then the precision of the resulting number is determined automatically from the input.
§Examples
Code below converts -0.1234567₈ × 10₈^3₈ given in radix 8 to ExactNum.
let mut cc = Consts::new().expect("Constants cache initialized.");
let n = ExactNum::convert_from_radix(
Sign::Neg,
&[1, 2, 3, 4, 5, 6, 7, 0],
3,
Radix::Oct,
64,
RoundingMode::None,
&mut cc);
assert!(!n.is_nan());
assert!(n.is_negative());§Errors
On error, the function returns NaN with the following associated error:
- MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- InvalidArgument: the precision is incorrect, or
digitscontains unacceptable digits for given radix, or wheneis less than EXPONENT_MIN or greater than EXPONENT_MAX.
Sourcepub fn convert_to_radix(
&self,
rdx: Radix,
rm: RoundingMode,
cc: &mut Consts,
) -> Result<(Sign, Vec<u8>, i32), Error>
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:
selfis Inf or NaN.
Sourcepub fn inexact(&self) -> bool
pub fn inexact(&self) -> bool
Returns true if self is inexact. The function returns false if self is Inf or NaN.
Sourcepub fn set_inexact(&mut self, inexact: bool)
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.
Sourcepub fn try_set_precision(
&mut self,
p: usize,
rm: RoundingMode,
s: usize,
) -> bool
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.
Sourcepub fn frexp(&self) -> (ExactNum, i32)
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)).
Sourcepub fn ldexp(&self, n: i32, p: usize, rm: RoundingMode) -> ExactNum
pub fn ldexp(&self, n: i32, p: usize, rm: RoundingMode) -> ExactNum
self · 2^n. Alias of Self::scalb.
Sourcepub fn logb(&self, p: usize, rm: RoundingMode) -> ExactNum
pub fn logb(&self, p: usize, rm: RoundingMode) -> ExactNum
floor(log2(|self|)) as a float. Zero becomes -Inf; Inf/NaN unchanged in kind.
Source§impl ExactNum
impl ExactNum
Sourcepub fn copysign(&self, sign: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
pub fn copysign(&self, sign: &ExactNum, p: usize, rm: RoundingMode) -> ExactNum
Returns a value with the magnitude of self and the sign of sign.
Sourcepub fn next_after(
&self,
toward: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
pub fn next_after( &self, toward: &ExactNum, p: usize, rm: RoundingMode, ) -> ExactNum
Returns the next representable value from self toward toward at precision p.
Sourcepub fn round(&self, n: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn sqrt(&self, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn cbrt(&self, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn ln(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn log2(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn log10(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn exp(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn exp2(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn exp10(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn rem_pi(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
pub fn rem_pi(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
Reduces self modulo 2π into the interval (-2π, 2π) using precision p and rounding mode rm.
This function requires constants cache cc for computing the result.
Sourcepub fn sin(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn cos(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn sin_cos(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> (ExactNum, ExactNum)
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.
Sourcepub fn tan(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn asin(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn acos(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn sinh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn cosh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn sinh_cosh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> (ExactNum, ExactNum)
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.
Sourcepub fn erf(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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±1when2|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| ≲ 4undermpfr-tests. Complexerfon the real axis uses the same oracle; GNU MPC has nompc_erf.
Sourcepub fn erfc(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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 - erfat extra working precision (same series / asymptotic aserf). - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). 1 ULP vs MPFR on|x| ≲ 4. - MPFR oracle: yes,
|x| ≲ 4undermpfr-tests.
Sourcepub fn gamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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 Γthenexp; 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.
Sourcepub fn ln_gamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn digamma(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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 MPFRdigammaonz > 0. - MPFR oracle: yes,
z > 0undermpfr-tests.
Sourcepub fn gammainc(
&self,
x: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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
xat working precision;+∞inxreturnsΓ(self). - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: identity
γ(s,x)=Γ(s)−Γ(s,x); upper usesmpfr_gamma_inc.
Sourcepub fn gammainc_upper(
&self,
x: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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;+∞inxreturns 0. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: yes,
mpfr_gamma_incundermpfr-tests.
Sourcepub fn ei(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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() > 6and|x| ≳ 0.7 p). - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: yes,
mpfr_eintundermpfr-tests.
Sourcepub fn si(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
pub fn si(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
Sine integral Si(self). +∞ → π/2, −∞ → −π/2.
§Precision
- Algorithm: series, or auxiliary
f,gasymptotic on the same cut asEi. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (
Siodd,Si(0)=0,Si(+∞)=π/2).
Sourcepub fn ci(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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,gasymptotic (same|x|cut asEi). Near-zero is a pole. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (identity / series golds; GNU MPFR has no
Si/Ci).
Sourcepub fn li(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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 (inheritsEiseries / asymptotic). - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (
li(e)=Ei(1)identity).
Sourcepub fn fresnel_s(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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,gwhen|x|.exponent() ≥ 8(or3 x² > p). - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (
Sodd,S(0)=0,S(+∞)=1/2).
Sourcepub fn fresnel_c(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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,gsplit asSelf::fresnel_s. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (same identities as
Self::fresnel_s).
Sourcepub fn ai(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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_aiundermpfr-tests.
Sourcepub fn ai_prime(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn bi_prime(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn bessel_j(
&self,
n: usize,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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 MPFRjnforn = 0,1,2. - MPFR oracle: yes,
n = 0,1,2undermpfr-tests.
Sourcepub fn bessel_j_nu(
&self,
nu: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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 toSelf::bessel_j. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (identity golds).
Sourcepub fn bessel_y(
&self,
nu: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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_ynforn = 0,1undermpfr-tests.
Sourcepub fn bessel_i(
&self,
nu: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn bessel_k(
&self,
nu: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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|asymptotick_asymptotic. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn elliptic_k(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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_Fduplication; capCARLSON_DUPE_MAX = 128. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (identity golds; GNU MPFR has no Carlson
K).
Sourcepub fn elliptic_e_complete(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn elliptic_f(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn elliptic_e(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn elliptic_pi_complete(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn elliptic_pi(
&self,
x: &ExactNum,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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.
Sourcepub fn jacobi_am(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_am( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
Jacobi amplitude am(self | m). Parameter m = k² ∈ [0, 1].
§Precision
- Algorithm: AGM / descending Landen; cap
JACOBI_AGM_MAX = 128. (m=0) is trig; (m=1) is hyperbolic. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no (identity golds; GNU MPFR has no Jacobi
sn).
Sourcepub fn jacobi_sn(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_sn( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
sn(self | m). Parameter m = k² ∈ [0, 1].
The inverse on (-K, K) is Self::elliptic_f: F(sn(u|m)|m) = u.
§Precision
- Algorithm: AGM amplitude; cap
JACOBI_AGM_MAX = 128. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn jacobi_cn(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_cn( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
cn(self | m). Parameter m = k² ∈ [0, 1].
§Precision
- Algorithm: AGM amplitude; cap
JACOBI_AGM_MAX = 128. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn jacobi_dn(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_dn( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
dn(self | m). Parameter m = k² ∈ [0, 1].
§Precision
- Algorithm: AGM amplitude; cap
JACOBI_AGM_MAX = 128. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn jacobi_cd(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_cd( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
cd(self | m) = cn / dn. Parameter m = k² ∈ [0, 1].
§Precision
- Algorithm: AGM amplitude; cap
JACOBI_AGM_MAX = 128. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn jacobi_ns(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_ns( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
ns(self | m) = 1/sn.
Sourcepub fn jacobi_nc(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_nc( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
nc(self | m) = 1/cn.
Sourcepub fn jacobi_nd(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_nd( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
nd(self | m) = 1/dn.
Sourcepub fn jacobi_sc(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_sc( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
sc(self | m) = sn/cn.
Sourcepub fn jacobi_sd(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_sd( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
sd(self | m) = sn/dn.
Sourcepub fn jacobi_cs(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_cs( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
cs(self | m) = cn/sn.
Sourcepub fn jacobi_ds(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_ds( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
ds(self | m) = dn/sn.
Sourcepub fn jacobi_dc(
&self,
m: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
pub fn jacobi_dc( &self, m: &ExactNum, p: usize, rm: RoundingMode, cc: &mut Consts, ) -> ExactNum
dc(self | m) = dn/cn.
Sourcepub fn legendre_p(&self, n: u32, p: usize, rm: RoundingMode) -> ExactNum
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. CapORTHOPOLY_N_MAX. - Bound: working-precision recurrence (not a Ziv leaf).
- MPFR oracle: no.
Sourcepub fn assoc_legendre_p(
&self,
n: u32,
m: i32,
p: usize,
rm: RoundingMode,
) -> ExactNum
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.
Sourcepub fn hypergeom_2f1(
&self,
b: &ExactNum,
c: &ExactNum,
z: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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 atz = 1; Pfaff / continuation. CapHYPERGEOM_TERM_MAX = 10_000. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY) when the series converges. - MPFR oracle: no.
Sourcepub fn betainc(
&self,
b: &ExactNum,
x: &ExactNum,
p: usize,
rm: RoundingMode,
cc: &mut Consts,
) -> ExactNum
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]fora > 0,b > 0. - Bound: Ziv correct-rounding (
MAX_PREC_RETRY). - MPFR oracle: no.
Sourcepub fn asinh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn acosh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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.
Sourcepub fn atanh(&self, p: usize, rm: RoundingMode, cc: &mut Consts) -> ExactNum
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§impl ExactNum
impl ExactNum
Sourcepub fn hermite_he(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn hermite_h(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn laguerre(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn gen_laguerre(
&self,
n: usize,
alpha: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
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.
Sourcepub fn chebyshev_t(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn chebyshev_u(&self, n: usize, p: usize, rm: RoundingMode) -> ExactNum
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.
Sourcepub fn gegenbauer(
&self,
n: usize,
lambda: &ExactNum,
p: usize,
rm: RoundingMode,
) -> ExactNum
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§impl ExactNum
impl ExactNum
Sourcepub fn parse_exact(s: &str) -> Option<ExactNum>
pub fn parse_exact(s: &str) -> Option<ExactNum>
Parse a decimal that is exact in binary (a dyadic rational). None if the
value is not a finite dyadic (so 0.1 is None here; use ExactRational::parse_exact).
Sourcepub fn format_exact(&self, rdx: Radix) -> Option<String>
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§
impl Eq for ExactNum
Source§impl PartialOrd for ExactNum
impl PartialOrd for ExactNum
Source§impl<'a> PartialOrd<&'a ExactNum> for ExactNum
impl<'a> PartialOrd<&'a ExactNum> for ExactNum
Auto Trait Implementations§
impl Freeze for ExactNum
impl RefUnwindSafe for ExactNum
impl Send for ExactNum
impl Sync for ExactNum
impl Unpin for ExactNum
impl UnsafeUnpin for ExactNum
impl UnwindSafe for ExactNum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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