Struct astro_float::BigFloatNumber
source · pub struct BigFloatNumber { /* private fields */ }
Expand description
A finite floating point number with mantissa of an arbitrary size, an exponent, and the sign. (BigFloatNumber will be removed in the future. BigFloat should be used instead).
Implementations§
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn convert_from_radix(
sign: Sign,
digits: &[u8],
e: Exponent,
rdx: Radix,
p: usize,
rm: RoundingMode
) -> Result<Self, Error>
pub fn convert_from_radix(
sign: Sign,
digits: &[u8],
e: Exponent,
rdx: Radix,
p: usize,
rm: RoundingMode
) -> Result<Self, Error>
Converts an array of digits in radix rdx
to BigFloatNumber 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.
Examples
Code below converts -0.1234567₈ × 10₈^3₈
given in radix 8 to BigFloatNumber.
#![allow(deprecated)]
use astro_float::{BigFloatNumber, Sign, RoundingMode, Radix};
let g = BigFloatNumber::convert_from_radix(
Sign::Neg,
&[1, 2, 3, 4, 5, 6, 7, 0],
3,
Radix::Oct,
64,
RoundingMode::None).unwrap();
let n = BigFloatNumber::from_f64(64, -83.591552734375).unwrap();
assert!(n.cmp(&g) == 0);
Errors
- 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
digits
contains unacceptable digits for given radix.
sourcepub fn convert_to_radix(
&self,
rdx: Radix,
rm: RoundingMode
) -> Result<(Sign, Vec<u8>, Exponent), Error>
pub fn convert_to_radix(
&self,
rdx: Radix,
rm: RoundingMode
) -> Result<(Sign, Vec<u8>, Exponent), 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
#![allow(deprecated)]
use astro_float::{BigFloatNumber, Sign, RoundingMode, Radix};
let n = BigFloatNumber::from_f64(64, 0.00012345678f64).unwrap();
let (s, m, e) = n.convert_to_radix(Radix::Dec, RoundingMode::None).unwrap();
assert_eq!(s, Sign::Pos);
assert_eq!(m, [1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, 4, 2]);
assert_eq!(e, -3);
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn new(p: usize) -> Result<Self, Error>
pub fn new(p: usize) -> Result<Self, Error>
Returns a new number with value of 0 and precision of p
bits. Precision is rounded upwards to the word size.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn max_value(p: usize) -> Result<Self, Error>
pub fn max_value(p: usize) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn min_value(p: usize) -> Result<Self, Error>
pub fn min_value(p: usize) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn min_positive(p: usize) -> Result<Self, Error>
pub fn min_positive(p: usize) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn min_positive_normal(p: usize) -> Result<Self, Error>
pub fn min_positive_normal(p: usize) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn from_word(d: Word, p: usize) -> Result<Self, Error>
pub fn from_word(d: Word, p: usize) -> Result<Self, Error>
Returns a new number with value d
and the precision p
. Precision is rounded upwards to the word size.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn neg(&self) -> Result<Self, Error>
pub fn neg(&self) -> Result<Self, Error>
Returns a copy of the number with the sign reversed.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn add(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn add(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: the precision is incorrect.
sourcepub fn sub(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn sub(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: the precision is incorrect.
sourcepub fn add_full_prec(&self, d2: &Self) -> Result<Self, Error>
pub fn add_full_prec(&self, d2: &Self) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn sub_full_prec(&self, d2: &Self) -> Result<Self, Error>
pub fn sub_full_prec(&self, d2: &Self) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn mul(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn mul(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: the precision is incorrect.
sourcepub fn mul_full_prec(&self, d2: &Self) -> Result<Self, Error>
pub fn mul_full_prec(&self, d2: &Self) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn div(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn div(&self, d2: &Self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- DivisionByZero:
d2
is zero. - ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: both
self
andd2
are zero or precision is incorrect.
sourcepub fn rem(&self, d2: &Self) -> Result<Self, Error>
pub fn rem(&self, d2: &Self) -> Result<Self, Error>
Returns the remainder of division of |self|
by |d2|
. The sign of the result is set to the sign of self
.
Errors
- DivisionByZero:
d2
is zero. - ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: both
self
andd2
are zero.
sourcepub fn cmp(&self, d2: &Self) -> i128
pub fn cmp(&self, d2: &Self) -> i128
Compares self
to d2
.
Returns positive if self
is greater than d2
, negative if self
is smaller than d2
, 0 otherwise.
sourcepub fn abs_cmp(&self, d2: &Self) -> i128
pub fn abs_cmp(&self, d2: &Self) -> 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 otherwise.
sourcepub fn abs(&self) -> Result<Self, Error>
pub fn abs(&self) -> Result<Self, Error>
Returns the absolute value of a number.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn from_f64(p: usize, f: f64) -> Result<Self, Error>
pub fn from_f64(p: usize, f: f64) -> Result<Self, Error>
Constructs a number with precision p
from f64 value.
Precision is rounded upwards to the word size.
Errors
- InvalidArgument: the precision is incorrect or
f
is NaN. - MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow:
f
is Inf.
sourcepub fn from_f32(p: usize, f: f32) -> Result<Self, Error>
pub fn from_f32(p: usize, f: f32) -> Result<Self, Error>
Constructs a number with precision p
from f32 value.
Precision is rounded upwards to the word size.
Errors
- InvalidArgument: the precision is incorrect or
f
is NaN. - MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow:
f
is Inf.
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 to_raw_parts(&self) -> (&[Word], usize, Sign, Exponent)
pub fn to_raw_parts(&self) -> (&[Word], usize, Sign, Exponent)
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, and exponent.
sourcepub fn from_raw_parts(
m: &[Word],
n: usize,
s: Sign,
e: Exponent
) -> Result<Self, Error>
pub fn from_raw_parts(
m: &[Word],
n: usize,
s: Sign,
e: Exponent
) -> Result<Self, Error>
Constructs a number from the raw parts:
m
is the mantisaa.n
is the number of significant bits in mantissa.s
is the sign.e
is the exponent.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument:
n
is larger than the number of bits inm
;n
is smaller than the number of bits inm
, butm
does not represent corresponding subnormal number mantissa;n
is smaller than the number of bits inm
, bute
is not the minimum possible exponent;n
or the size ofm
is too large (larger than isize::MAX / 2 + EXPONENT_MIN).
sourcepub fn from_words(m: &[Word], s: Sign, e: Exponent) -> Result<Self, Error>
pub fn from_words(m: &[Word], s: Sign, e: Exponent) -> Result<Self, Error>
Constructs a number from the slice of words:
m
is the mantissa.s
is the sign.e
is the exponent.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
- InvalidArgument: size of
m
is larger than isize::MAX / 2 + EXPONENT_MIN.
sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if self
is positive.
sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if self
is negative.
sourcepub fn get_exponent(&self) -> Exponent
pub fn get_exponent(&self) -> Exponent
Returns the exponent of self
.
sourcepub fn floor(&self) -> Result<Self, Error>
pub fn floor(&self) -> Result<Self, Error>
Returns the largest integer less than or equal to self
.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn ceil(&self) -> Result<Self, Error>
pub fn ceil(&self) -> Result<Self, Error>
Returns the smallest integer greater than or equal to self
.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn fract(&self) -> Result<Self, Error>
pub fn fract(&self) -> Result<Self, Error>
Returns fractional part of a number.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
sourcepub fn set_exponent(&mut self, e: Exponent)
pub fn set_exponent(&mut self, e: Exponent)
Sets the exponent of self
.
Note that if self
is subnormal, the exponent may not change, but the mantissa will shift instead.
See example below.
Examples
#![allow(deprecated)]
use astro_float::BigFloatNumber;
use astro_float::EXPONENT_MIN;
// construct a subnormal value.
let mut n = BigFloatNumber::min_positive(128).unwrap();
assert_eq!(n.get_exponent(), EXPONENT_MIN);
assert_eq!(n.get_precision(), 1);
// increase exponent.
n.set_exponent(n.get_exponent() + 1);
// the outcome for subnormal number.
assert_eq!(n.get_exponent(), EXPONENT_MIN);
assert_eq!(n.get_precision(), 2);
sourcepub fn get_mantissa_max_bit_len(&self) -> usize
pub fn get_mantissa_max_bit_len(&self) -> usize
Returns the maximum mantissa length of self
in bits regardless of whether self
is normal or subnormal.
sourcepub fn get_precision(&self) -> usize
pub fn get_precision(&self) -> usize
Returns the number of significant bits used in the mantissa. Normal numbers use all bits of the mantissa. Subnormal numbers use fewer bits than the mantissa can hold.
sourcepub fn round(&self, n: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn round(&self, n: usize, rm: RoundingMode) -> Result<Self, Error>
Returns the rounded number with n
binary positions in the fractional part of the number using rounding mode rm
.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow: rounding causes exponent overflow.
sourcepub fn random_normal(
p: usize,
exp_from: Exponent,
exp_to: Exponent
) -> Result<Self, Error>
pub fn random_normal(
p: usize,
exp_from: Exponent,
exp_to: Exponent
) -> Result<Self, Error>
Returns a random normalized (not subnormal) BigFloat number with exponent in the range
from exp_from
to exp_to
inclusive. The sign can be positive and negative. Zero is excluded.
Precision is rounded upwards to the word size.
Function does not follow any specific distribution law.
The intended use of this function is for testing.
Errors
- InvalidArgument: the precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
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) -> Result<Self, Error>
pub fn reciprocal(&self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow: rounding caused exponent overflow.
- InvalidArgument: the precision is incorrect.
sourcepub fn get_mantissa_digits(&self) -> &[Word]
pub fn get_mantissa_digits(&self) -> &[Word]
Returns the raw mantissa words of a number.
source§impl BigFloatNumber
impl BigFloatNumber
source§impl BigFloatNumber
impl BigFloatNumber
source§impl BigFloatNumber
impl BigFloatNumber
source§impl BigFloatNumber
impl BigFloatNumber
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn acos(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn acos(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: argument is greater than 1 or smaller than -1, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn acosh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn acosh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: when
self
< 1, or the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn asin(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn asin(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: argument is greater than 1 or smaller than -1, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn asinh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn asinh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn atan(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn atan(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn atanh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn atanh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: when |
self
| > 1, or the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn cbrt(&self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn cbrt(&self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn cos(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn cos(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn cosh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn cosh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn ln(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn ln(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the argument is zero or negative, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
sourcepub fn log2(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn log2(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the argument is zero or negative, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
sourcepub fn log10(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn log10(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the argument is zero or negative, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
sourcepub fn log(
&self,
n: &Self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn log(
&self,
n: &Self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- InvalidArgument: the argument is zero or negative, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
- DivisionByZero:
n
= 1
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn exp(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn exp(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
sourcepub fn powi(&self, n: usize, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn powi(&self, n: usize, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
sourcepub fn pow(
&self,
n: &Self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn pow(
&self,
n: &Self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument:
self
is negative, or the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn sin(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn sin(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
sourcepub fn sin_series(
self,
rm: RoundingMode,
with_correction: bool
) -> Result<Self, Error>
pub fn sin_series(
self,
rm: RoundingMode,
with_correction: bool
) -> Result<Self, Error>
sine using series
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn sinh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn sinh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn sqrt(&self, p: usize, rm: RoundingMode) -> Result<Self, Error>
pub fn sqrt(&self, p: usize, rm: RoundingMode) -> Result<Self, Error>
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.
Errors
- InvalidArgument: argument is negative, or the precision is incorrect.
- MemoryAllocation: failed to allocate memory.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn tan(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn tan(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn tanh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
pub fn tanh(
&self,
p: usize,
rm: RoundingMode,
cc: &mut Consts
) -> Result<Self, Error>
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.
Errors
- ExponentOverflow: the result is too large or too small number.
- MemoryAllocation: failed to allocate memory.
- InvalidArgument: the precision is incorrect.
source§impl BigFloatNumber
impl BigFloatNumber
sourcepub fn parse(
s: &str,
rdx: Radix,
p: usize,
rm: RoundingMode
) -> Result<Self, Error>
pub fn parse(
s: &str,
rdx: Radix,
p: usize,
rm: RoundingMode
) -> Result<Self, Error>
Parses the number from the string s
using radix rdx
, precision p
, 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
- InvalidArgument: failed to parse input or precision is incorrect.
- MemoryAllocation: failed to allocate memory for mantissa.
- ExponentOverflow: the resulting exponent becomes greater than the maximum allowed value for the exponent.
sourcepub fn format(&self, rdx: Radix, rm: RoundingMode) -> Result<String, Error>
pub fn format(&self, rdx: Radix, rm: RoundingMode) -> 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.