pub struct BigFloat { /* private fields */ }Expand description
Native arbitrary-precision binary float.
BigFloat represents (-1)^sign * mantissa * 2^exponent with precision
significant bits. See the module-level documentation for the full
invariant list.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let a = BigFloat::from_i64(3, 8, RoundingMode::HalfEven);
let b = BigFloat::from_i64(5, 8, RoundingMode::HalfEven);
let sum = &a + &b;
assert_eq!(sum.to_f64(), 8.0);Implementations§
Source§impl BigFloat
impl BigFloat
Sourcepub fn atan(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn atan(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return atan(self) at prec bits using the given rounding mode.
The result lies in (−π/2, π/2).
§Errors
Propagates sqrt or division errors (only if internal invariants break, which should not happen for well-formed inputs).
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let one = BigFloat::from_i64(1, 64, RoundingMode::HalfEven);
let a = one.atan(64, RoundingMode::HalfEven).expect("atan(1)");
// atan(1) = π/4 ≈ 0.7853981633974483
assert!((a.to_f64() - std::f64::consts::FRAC_PI_4).abs() < 1e-14);Sourcepub fn atan2(
&self,
x: &BigFloat,
prec: u32,
mode: RoundingMode,
) -> OxiNumResult<BigFloat>
pub fn atan2( &self, x: &BigFloat, prec: u32, mode: RoundingMode, ) -> OxiNumResult<BigFloat>
Return atan2(self, x) at prec bits using the given rounding mode.
Conventionally atan2(y, x) — self is y and x is the argument.
The result lies in (−π, π].
§Special cases
atan2(0, 0) = 0(by convention, not mathematically defined).atan2(y, 0) = ±π/2depending on sign ofy.
§Errors
Propagates errors from BigFloat::atan.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let y = BigFloat::from_i64(1, 64, RoundingMode::HalfEven);
let x = BigFloat::from_i64(1, 64, RoundingMode::HalfEven);
let a = y.atan2(&x, 64, RoundingMode::HalfEven).expect("atan2(1,1)");
// atan2(1,1) = π/4 ≈ 0.7853981633974483
assert!((a.to_f64() - std::f64::consts::FRAC_PI_4).abs() < 1e-14);Source§impl BigFloat
impl BigFloat
Sourcepub fn nan(prec: u32) -> Self
pub fn nan(prec: u32) -> Self
Create a canonical NaN at prec bits. NaN’s sign is always Positive.
Sourcepub fn neg_infinity(prec: u32) -> Self
pub fn neg_infinity(prec: u32) -> Self
Create negative infinity (−∞) at prec bits.
Sourcepub fn from_parts(
sign: Sign,
mantissa: BigUint,
exponent: i64,
prec: u32,
mode: RoundingMode,
) -> Self
pub fn from_parts( sign: Sign, mantissa: BigUint, exponent: i64, prec: u32, mode: RoundingMode, ) -> Self
Construct directly from already-validated parts.
The result is normalized (trailing-zero bits migrated into the
exponent) and then rounded to prec bits if the normalized mantissa
is wider than prec. If the normalized mantissa is narrower, it is
left-padded so mantissa.bit_length() == prec while preserving the
mathematical value.
Used by every higher-level constructor (from_i64, from_f64,
arithmetic) — call this whenever you need to land back at the
canonical invariant from arbitrary parts.
Sourcepub fn sign(&self) -> Sign
pub fn sign(&self) -> Sign
Returns the sign.
For the canonical zero, the sign is always Sign::Positive.
Sourcepub fn exponent(&self) -> i64
pub fn exponent(&self) -> i64
Returns the binary exponent (the power of 2 the mantissa is scaled by).
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true if this value is the canonical zero.
NaN and Inf have mantissa = 0 internally, so this check requires
testing the class field first.
Sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Returns true if this value is infinite (+∞ or −∞).
Sourcepub fn is_normal(&self) -> bool
pub fn is_normal(&self) -> bool
Returns true for finite non-zero values.
Arbitrary-precision floats have no Subnormal category — every nonzero
finite value is Normal.
Sourcepub fn classify(&self) -> FpCategory
pub fn classify(&self) -> FpCategory
Returns the IEEE 754 float class.
FpCategory::Subnormal is never returned: there is no fixed exponent
range in arbitrary-precision arithmetic, so every nonzero finite value
is Normal.
Sourcepub fn is_sign_positive(&self) -> bool
pub fn is_sign_positive(&self) -> bool
Returns true for positive and NaN values (NaN has canonical positive sign).
Note: unlike f64, the single canonical zero has is_sign_positive() == true.
Sourcepub fn is_sign_negative(&self) -> bool
pub fn is_sign_negative(&self) -> bool
Returns true only for negative-sign values (negative Inf or negative finite).
Note: canonical zero has is_sign_negative() == false (no signed zero).
Sourcepub fn abs(&self) -> Self
pub fn abs(&self) -> Self
Returns the absolute value (sign forced to Sign::Positive).
Sourcepub fn neg(&self) -> Self
pub fn neg(&self) -> Self
Returns the additive inverse.
Negating the canonical zero yields the canonical zero (sign stays
Positive). Negating NaN returns NaN unchanged (the canonical NaN
always has sign Positive).
Sourcepub fn with_precision(self, prec: u32, mode: RoundingMode) -> Self
pub fn with_precision(self, prec: u32, mode: RoundingMode) -> Self
Change the precision, rounding the mantissa with mode if narrowing.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let a = BigFloat::from_i64(7, 8, RoundingMode::HalfEven);
let b = a.with_precision(64, RoundingMode::HalfEven);
assert_eq!(b.precision(), 64);
assert_eq!(b.to_f64(), 7.0);Sourcepub fn round_to_precision(self, prec: u32, mode: RoundingMode) -> Self
pub fn round_to_precision(self, prec: u32, mode: RoundingMode) -> Self
Round the mantissa so that, after normalization, it has exactly prec
significant bits.
If the current mantissa has fewer bits than prec, the result is
left-padded; the mathematical value is unchanged. If it has more bits,
the low bits are discarded according to mode.
Source§impl BigFloat
impl BigFloat
Sourcepub fn total_cmp(&self, other: &Self) -> Ordering
pub fn total_cmp(&self, other: &Self) -> Ordering
IEEE 754-style total order, suitable for sorting.
Sequence: −Inf < (negative finite) < zero < (positive finite) < +Inf < NaN.
Because this type has a single canonical zero and a single canonical NaN,
total_cmp(NaN, NaN) == Equal and total_cmp(+Inf, NaN) == Less.
Source§impl BigFloat
impl BigFloat
Sourcepub fn add_ref(&self, other: &BigFloat) -> BigFloat
pub fn add_ref(&self, other: &BigFloat) -> BigFloat
Return self + other, rounding the result to
max(self.precision, other.precision) using banker’s rounding.
Sourcepub fn add_ref_with_mode(
&self,
other: &BigFloat,
mode: RoundingMode,
) -> BigFloat
pub fn add_ref_with_mode( &self, other: &BigFloat, mode: RoundingMode, ) -> BigFloat
Return self + other, rounding the result to
max(self.precision, other.precision) using the chosen rounding mode.
Sourcepub fn sub_ref(&self, other: &BigFloat) -> BigFloat
pub fn sub_ref(&self, other: &BigFloat) -> BigFloat
Return self - other at max(p_self, p_other) precision, banker’s
rounding.
Sourcepub fn sub_ref_with_mode(
&self,
other: &BigFloat,
mode: RoundingMode,
) -> BigFloat
pub fn sub_ref_with_mode( &self, other: &BigFloat, mode: RoundingMode, ) -> BigFloat
Return self - other at max(p_self, p_other) precision with the
given rounding mode.
Source§impl BigFloat
impl BigFloat
Sourcepub fn to_bigint_trunc(&self) -> BigInt
pub fn to_bigint_trunc(&self) -> BigInt
Convert to BigInt by truncating toward zero (round-toward-zero).
Returns the integer part of self, discarding any fractional bits.
Non-finite values (NaN, ±Inf) have no integer representation.
This method returns BigInt::zero() as a documented lossy fallback
for those inputs; callers that may encounter non-finite values should
use BigFloat::is_finite to guard before calling.
§Examples
use oxinum_float::native::BigFloat;
use oxinum_int::native::BigInt;
let x = BigFloat::from_f64(3.7, 64).expect("3.7");
assert_eq!(x.to_bigint_trunc(), BigInt::from(3i64));
let y = BigFloat::from_f64(-3.7, 64).expect("-3.7");
assert_eq!(y.to_bigint_trunc(), BigInt::from(-3i64));
// Non-finite values return zero (lossy).
assert_eq!(BigFloat::nan(53).to_bigint_trunc(), BigInt::zero());
assert_eq!(BigFloat::infinity(53).to_bigint_trunc(), BigInt::zero());Sourcepub fn to_bigint_floor(&self) -> BigInt
pub fn to_bigint_floor(&self) -> BigInt
Convert to BigInt by rounding toward negative infinity (floor).
For negative values with a non-zero fractional part, the result is one less than the truncation (i.e. more negative).
§Examples
use oxinum_float::native::BigFloat;
use oxinum_int::native::BigInt;
let x = BigFloat::from_f64(3.7, 64).expect("3.7");
assert_eq!(x.to_bigint_floor(), BigInt::from(3i64));
let y = BigFloat::from_f64(-3.7, 64).expect("-3.7");
assert_eq!(y.to_bigint_floor(), BigInt::from(-4i64));Sourcepub fn to_bigint_ceil(&self) -> BigInt
pub fn to_bigint_ceil(&self) -> BigInt
Convert to BigInt by rounding toward positive infinity (ceiling).
For positive values with a non-zero fractional part, the result is one more than the truncation.
§Examples
use oxinum_float::native::BigFloat;
use oxinum_int::native::BigInt;
let x = BigFloat::from_f64(3.7, 64).expect("3.7");
assert_eq!(x.to_bigint_ceil(), BigInt::from(4i64));
let y = BigFloat::from_f64(-3.7, 64).expect("-3.7");
assert_eq!(y.to_bigint_ceil(), BigInt::from(-3i64));Sourcepub fn to_bigint_round(&self) -> BigInt
pub fn to_bigint_round(&self) -> BigInt
Convert to BigInt by rounding half-away-from-zero.
- Fractional part < 1/2: truncate toward zero.
- Fractional part == 1/2: round away from zero (ties-away).
- Fractional part > 1/2: round away from zero.
§Examples
use oxinum_float::native::BigFloat;
use oxinum_int::native::BigInt;
let x = BigFloat::from_f64(3.7, 64).expect("3.7");
assert_eq!(x.to_bigint_round(), BigInt::from(4i64));
let y = BigFloat::from_f64(-3.7, 64).expect("-3.7");
assert_eq!(y.to_bigint_round(), BigInt::from(-4i64));Source§impl BigFloat
impl BigFloat
Sourcepub fn from_i64(n: i64, prec: u32, mode: RoundingMode) -> Self
pub fn from_i64(n: i64, prec: u32, mode: RoundingMode) -> Self
Encode the integer n as a BigFloat at prec bits of precision.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let a = BigFloat::from_i64(-42, 16, RoundingMode::HalfEven);
assert_eq!(a.to_f64(), -42.0);Sourcepub fn from_f64(x: f64, prec: u32) -> OxiNumResult<Self>
pub fn from_f64(x: f64, prec: u32) -> OxiNumResult<Self>
Decompose an IEEE-754 f64 value into a BigFloat at prec bits.
At prec >= 53 the decomposition is exact (no rounding occurs). The
rounding mode used for any narrowing is RoundingMode::HalfEven.
§Errors
Returns OxiNumError::Parse if x is NaN or infinite — native
BigFloat does not yet model those special values.
§Examples
use oxinum_float::native::BigFloat;
let half = BigFloat::from_f64(0.5, 1).expect("0.5 fits in 1 bit");
assert_eq!(half.to_f64(), 0.5);Source§impl BigFloat
impl BigFloat
Sourcepub fn from_bigint(n: &BigInt, prec: u32, mode: RoundingMode) -> Self
pub fn from_bigint(n: &BigInt, prec: u32, mode: RoundingMode) -> Self
Convert a BigInt (signed arbitrary-precision integer) to BigFloat
at prec bits of precision using the given rounding mode.
The conversion is exact when prec >= n.magnitude().bit_length();
otherwise the result is rounded according to mode.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
use oxinum_int::native::BigInt;
let n = BigInt::from(-42i64);
let f = BigFloat::from_bigint(&n, 64, RoundingMode::HalfEven);
assert_eq!(f.to_f64(), -42.0);Sourcepub fn from_biguint(n: &BigUint, prec: u32, mode: RoundingMode) -> Self
pub fn from_biguint(n: &BigUint, prec: u32, mode: RoundingMode) -> Self
Convert a BigUint (non-negative arbitrary-precision integer) to
BigFloat at prec bits of precision using the given rounding mode.
The conversion is exact when prec >= n.bit_length(); otherwise the
result is rounded according to mode.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
use oxinum_int::native::BigUint;
let n = BigUint::from_u64(1024);
let f = BigFloat::from_biguint(&n, 64, RoundingMode::HalfEven);
assert_eq!(f.to_f64(), 1024.0);Source§impl BigFloat
impl BigFloat
Sourcepub fn div_ref(&self, other: &BigFloat) -> OxiNumResult<BigFloat>
pub fn div_ref(&self, other: &BigFloat) -> OxiNumResult<BigFloat>
Return self / other at max(p_self, p_other) precision using
banker’s rounding.
§Errors
Returns OxiNumError::DivByZero if other is the canonical zero.
Sourcepub fn div_ref_with_mode(
&self,
other: &BigFloat,
mode: RoundingMode,
) -> OxiNumResult<BigFloat>
pub fn div_ref_with_mode( &self, other: &BigFloat, mode: RoundingMode, ) -> OxiNumResult<BigFloat>
Return self / other at max(p_self, p_other) precision with the
given rounding mode.
§Errors
Returns OxiNumError::DivByZero if other is the canonical zero.
Source§impl BigFloat
impl BigFloat
Sourcepub fn exp(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn exp(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return e^self at prec bits using the chosen rounding mode.
§Errors
OxiNumError::Overflowifselfis so large that the result exceeds the representable range (|x| > 745).
§Examples
use oxinum_float::native::{BigFloat, RoundingMode, e_const};
let one = BigFloat::from_i64(1, 100, RoundingMode::HalfEven);
let result = one.exp(100, RoundingMode::HalfEven).expect("exp(1)");
let e = e_const(100).expect("e_const");
let diff = (result.to_f64() - e.to_f64()).abs();
assert!(diff < 1e-14);Source§impl BigFloat
impl BigFloat
Sourcepub fn ln(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn ln(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return ln(self) at prec bits using the chosen rounding mode.
§Errors
OxiNumError::Domainifself <= 0.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let one = BigFloat::from_i64(1, 64, RoundingMode::HalfEven);
let result = one.ln(64, RoundingMode::HalfEven).expect("ln(1)");
assert!(result.is_zero());Source§impl BigFloat
impl BigFloat
Sourcepub fn mul_ref(&self, other: &BigFloat) -> BigFloat
pub fn mul_ref(&self, other: &BigFloat) -> BigFloat
Return self * other, rounding the result to
max(self.precision, other.precision) using banker’s rounding.
Sourcepub fn mul_ref_with_mode(
&self,
other: &BigFloat,
mode: RoundingMode,
) -> BigFloat
pub fn mul_ref_with_mode( &self, other: &BigFloat, mode: RoundingMode, ) -> BigFloat
Return self * other, rounding the result to
max(self.precision, other.precision) using the chosen rounding mode.
Source§impl BigFloat
impl BigFloat
Sourcepub fn sqrt(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<Self>
pub fn sqrt(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<Self>
Return sqrt(self) at prec bits using the chosen rounding mode.
§Errors
OxiNumError::Domainifself < 0(real-valued sqrt is undefined for negative inputs).
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let four = BigFloat::from_i64(4, 32, RoundingMode::HalfEven);
let two = four.sqrt(32, RoundingMode::HalfEven).expect("sqrt(4) is real");
assert_eq!(two.to_f64(), 2.0);Source§impl BigFloat
impl BigFloat
Sourcepub fn to_scientific_string(&self, sig_digits: usize) -> String
pub fn to_scientific_string(&self, sig_digits: usize) -> String
Render this value in decimal scientific notation with sig_digits
significant digits: d.ddd…e±E (a single digit before the point).
The value is rounded (ties to even) to sig_digits significant decimal
digits. sig_digits is clamped to at least 1.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let x = BigFloat::from_i64(12345, 64, RoundingMode::HalfEven);
assert_eq!(x.to_scientific_string(5), "1.2345e4");
assert_eq!(x.to_scientific_string(1), "1e4");Sourcepub fn to_engineering_string(&self, sig_digits: usize) -> String
pub fn to_engineering_string(&self, sig_digits: usize) -> String
Render this value in decimal engineering notation with sig_digits
significant digits.
Engineering notation is scientific notation constrained so the decimal
exponent is always a multiple of three and the displayed mantissa lies
in [1, 1000). The mantissa therefore carries one, two, or three digits
before the point.
The value is rounded (ties to even) to sig_digits significant decimal
digits. sig_digits is clamped to at least 1.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let x = BigFloat::from_i64(12345, 64, RoundingMode::HalfEven);
assert_eq!(x.to_engineering_string(5), "12.345e3");Source§impl BigFloat
impl BigFloat
Sourcepub fn to_hex_string(&self) -> String
pub fn to_hex_string(&self) -> String
Render this value as a C99 %a-style hexadecimal float string:
±0x1.<hex-frac>p±<binexp>.
The rendering is binary-exact: the leading mantissa bit becomes the
1 before the point, the remaining bits are grouped (MSB-first) into
4-bit hex nibbles after the point, and the p exponent is the binary
exponent of the leading bit. The canonical zero renders as 0x0p0.
BigFloat::from_hex_float is the exact inverse, so
from_hex_float(x.to_hex_string()) reproduces x bit-for-bit.
§Examples
use oxinum_float::native::BigFloat;
let x = BigFloat::from_f64(12.0, 53).expect("finite");
// 12 = 1.1000…b × 2^3 → 0x1.8p3
assert_eq!(x.to_hex_string(), "0x1.8p3");Sourcepub fn from_hex_float(s: &str, prec: u32) -> OxiNumResult<Self>
pub fn from_hex_float(s: &str, prec: u32) -> OxiNumResult<Self>
Parse a C99 %a-style hexadecimal float string into a BigFloat at
prec bits of precision.
Accepts ±0x<hexint>[.<hexfrac>]p±<decexp> (the 0x/0X prefix, at
least one hex digit overall, and the p/P binary exponent are all
mandatory). The parse is binary-exact before the final
normalization/rounding to prec bits.
§Errors
Returns OxiNumError::Parse on any malformed input: a missing 0x
prefix, a missing p exponent, non-hex digits in the significand, a
non-decimal exponent, or stray characters.
§Examples
use oxinum_float::native::BigFloat;
// 0x1.8p3 = 1.5 × 2^3 = 12.
let x = BigFloat::from_hex_float("0x1.8p3", 53).expect("valid hex float");
assert_eq!(x.to_f64(), 12.0);Source§impl BigFloat
impl BigFloat
Sourcepub fn ln_agm(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn ln_agm(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return ln(self) at prec bits using the AGM algorithm.
This is algorithmically distinct from BigFloat::ln, which uses
Newton-Raphson iteration on the exponential. The AGM method converges
quadratically from the start (no f64 seed required) and avoids calling
exp internally, making it independent of the Taylor-series path.
§Errors
OxiNumError::Domainifself <= 0orprec == 0.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let two = BigFloat::from_i64(2, 64, RoundingMode::HalfEven);
let result = two.ln_agm(64, RoundingMode::HalfEven).expect("ln_agm(2)");
assert!((result.to_f64() - std::f64::consts::LN_2).abs() < 1e-14);Source§impl BigFloat
impl BigFloat
Sourcepub fn pow(
&self,
exp: &BigFloat,
prec: u32,
mode: RoundingMode,
) -> OxiNumResult<BigFloat>
pub fn pow( &self, exp: &BigFloat, prec: u32, mode: RoundingMode, ) -> OxiNumResult<BigFloat>
Return self^exp at prec bits using the chosen rounding mode.
§Special cases
x^0 = 1for anyx(includingx = 0).0^pos = 0.0^neg→OxiNumError::Domain.- Fractional exponent with non-positive base →
OxiNumError::Domain.
§Errors
OxiNumError::Domain— domain violation (negative base with fractional exponent, or zero base with negative exponent).OxiNumError::Overflow— propagated fromBigFloat::expif the intermediateexp * ln(self)exceeds the representable range.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let two = BigFloat::from_i64(2, 100, RoundingMode::HalfEven);
let ten = BigFloat::from_i64(10, 100, RoundingMode::HalfEven);
let result = two.pow(&ten, 100, RoundingMode::HalfEven).expect("2^10");
assert!((result.to_f64() - 1024.0).abs() < 1e-10);Source§impl BigFloat
impl BigFloat
Sourcepub fn log(
&self,
base: &BigFloat,
prec: u32,
mode: RoundingMode,
) -> OxiNumResult<BigFloat>
pub fn log( &self, base: &BigFloat, prec: u32, mode: RoundingMode, ) -> OxiNumResult<BigFloat>
Return log_base(self) (i.e. the logarithm of self in the given
base) at prec bits using the chosen rounding mode.
Computed as ln(self) / ln(base).
§Errors
OxiNumError::Domain—self <= 0,base <= 0, orbase == 1.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let hundred = BigFloat::from_i64(100, 100, RoundingMode::HalfEven);
let ten = BigFloat::from_i64(10, 100, RoundingMode::HalfEven);
let result = hundred.log(&ten, 100, RoundingMode::HalfEven).expect("log_10(100)");
assert!((result.to_f64() - 2.0).abs() < 1e-14);Source§impl BigFloat
impl BigFloat
Sourcepub fn sin(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn sin(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return sin(self) at prec bits using the given rounding mode.
Uses argument reduction mod π/2 and a Taylor series convergent for
|u| ≤ π/4.
§Errors
OxiNumError::Precisionif|self|is too large for the internal argument-reduction step (approximately|x| > 2^62 · π/2 ≈ 7.2·10^18).
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let zero = BigFloat::zero(64);
let s = zero.sin(64, RoundingMode::HalfEven).expect("sin(0)");
assert!(s.is_zero());Sourcepub fn cos(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn cos(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return cos(self) at prec bits using the given rounding mode.
§Errors
Same as BigFloat::sin.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let zero = BigFloat::zero(64);
let c = zero.cos(64, RoundingMode::HalfEven).expect("cos(0)");
assert_eq!(c.to_f64(), 1.0);Sourcepub fn tan(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
pub fn tan(&self, prec: u32, mode: RoundingMode) -> OxiNumResult<BigFloat>
Return tan(self) at prec bits using the given rounding mode.
§Errors
OxiNumError::Domainifcos(self) = 0(i.e.self = π/2 + k·π).OxiNumError::Precisionfor very large|self|.
§Examples
use oxinum_float::native::{BigFloat, RoundingMode};
let pi_over_4 = {
use oxinum_float::native::pi;
let p = pi(64).expect("pi");
let four = BigFloat::from_i64(4, 64, RoundingMode::HalfEven);
p.div_ref(&four).expect("div")
};
let t = pi_over_4.tan(64, RoundingMode::HalfEven).expect("tan(π/4)");
assert!((t.to_f64() - 1.0).abs() < 1e-14);Trait Implementations§
Source§impl AddAssign<&BigFloat> for BigFloat
impl AddAssign<&BigFloat> for BigFloat
Source§fn add_assign(&mut self, rhs: &BigFloat)
fn add_assign(&mut self, rhs: &BigFloat)
+= operation. Read moreSource§impl AddAssign for BigFloat
impl AddAssign for BigFloat
Source§fn add_assign(&mut self, rhs: BigFloat)
fn add_assign(&mut self, rhs: BigFloat)
+= operation. Read moreSource§impl Display for BigFloat
impl Display for BigFloat
Source§fn fmt(&self, f: &mut Formatter<'_>) -> Result
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Hex-float-ish display. Always exact, always short:
<sign>0xb<binary-mantissa>p<exponent>
where <binary-mantissa> is the mantissa written in base 2 (MSB
first). The 0xb literal prefix is intentional: it visually marks the
value as “binary hex-float”, distinct from the C99 0x<hex>p<exp>
format.
Non-finite values display as NaN, inf, or -inf.
Source§impl DivAssign<&BigFloat> for BigFloat
impl DivAssign<&BigFloat> for BigFloat
Source§fn div_assign(&mut self, rhs: &BigFloat)
fn div_assign(&mut self, rhs: &BigFloat)
/= operation. Read moreSource§impl DivAssign for BigFloat
impl DivAssign for BigFloat
Source§fn div_assign(&mut self, rhs: BigFloat)
fn div_assign(&mut self, rhs: BigFloat)
/= operation. Read moreSource§impl From<i64> for BigFloat
impl From<i64> for BigFloat
Source§fn from(n: i64) -> Self
fn from(n: i64) -> Self
Encodes n at 64 bits of precision with banker’s rounding.
Use BigFloat::from_i64 for explicit precision control.
Source§impl MulAssign<&BigFloat> for BigFloat
impl MulAssign<&BigFloat> for BigFloat
Source§fn mul_assign(&mut self, rhs: &BigFloat)
fn mul_assign(&mut self, rhs: &BigFloat)
*= operation. Read moreSource§impl MulAssign for BigFloat
impl MulAssign for BigFloat
Source§fn mul_assign(&mut self, rhs: BigFloat)
fn mul_assign(&mut self, rhs: BigFloat)
*= operation. Read moreSource§impl OxiNum for BigFloat
impl OxiNum for BigFloat
Source§fn is_zero(&self) -> bool
fn is_zero(&self) -> bool
Returns true if this value is the canonical zero.
Delegates to the inherent BigFloat::is_zero to avoid any
trait-method ambiguity.
Source§fn is_one(&self) -> bool
fn is_one(&self) -> bool
Returns true if this value is exactly 1.
Uses normalized equality: a BigFloat at precision P represents 1
when its mantissa encodes 2^(P-1) and its exponent is -(P-1) (the
normalization invariant pins mantissa.bit_length() == P). This is
equivalent to comparing against BigFloat::from_i64(1, P, HalfEven),
which produces the identical normalized representation.
The comparison must use self.precision() so that the constructed 1
has the same number of mantissa bits — two BigFloats with different
precisions representing the value 1 have different mantissa/exponent
pairs and would compare unequal (precision is excluded from PartialEq
on the struct fields, but the mathematical value is the same; the
normalized encoding, however, pins the high bit, so the bit widths must
agree for field-level equality).
Source§impl OxiSigned for BigFloat
impl OxiSigned for BigFloat
Source§fn signum(&self) -> Sign
fn signum(&self) -> Sign
Returns the sign of this value as Sign::Positive or
Sign::Negative.
Delegates to the inherent sign() method (returns Sign directly)
rather than the inherent signum() (returns i32) to avoid any
implicit coercion and to satisfy the trait’s -> Sign return type.
Source§fn abs(&self) -> Self
fn abs(&self) -> Self
Returns the absolute value (sign forced to Sign::Positive).
Delegates to the inherent BigFloat::abs.
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
true if this value is negative.Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
true if this value is positive (and not zero).Source§impl PartialOrd for BigFloat
impl PartialOrd for BigFloat
Source§impl RemAssign<&BigFloat> for BigFloat
impl RemAssign<&BigFloat> for BigFloat
Source§fn rem_assign(&mut self, rhs: &BigFloat)
fn rem_assign(&mut self, rhs: &BigFloat)
%= operation. Read moreSource§impl RemAssign for BigFloat
impl RemAssign for BigFloat
Source§fn rem_assign(&mut self, rhs: BigFloat)
fn rem_assign(&mut self, rhs: BigFloat)
%= operation. Read moreSource§impl SubAssign<&BigFloat> for BigFloat
impl SubAssign<&BigFloat> for BigFloat
Source§fn sub_assign(&mut self, rhs: &BigFloat)
fn sub_assign(&mut self, rhs: &BigFloat)
-= operation. Read more