Skip to main content

Crate bigfloat

Crate bigfloat 

Source
Expand description

§bigfloat

A safe, production-ready wrapper around MPFR for arbitrary-precision floating-point arithmetic.

This crate provides a BigFloat type that supports high‑precision floating‑point operations. All basic arithmetic (addition, subtraction, multiplication, division) is available through operator overloading, and many mathematical functions (such as sqrt, sin, log, factorial, constants, etc.) are exposed as free functions. Precision can be specified either by the number of bits or by the desired number of decimal digits.

§Examples

use bigfloat::*;

let x = "123.456".to_bigfloat(256);
let y = "789.012".to_bigfloat(256);
let sum = &x + &y;
assert_eq!(sum.to_string(10), "912.468");

let pi = const_pi(Some(50));
println!("π ≈ {pi}");

Structs§

BigFloat
An arbitrary‑precision floating‑point number backed by an MPFR variable.

Traits§

MpfrInput
Trait for types that can be converted into a BigFloat.

Functions§

acos
Returns the arccosine (inverse cosine) of n radians.
add
Returns the sum of two values, with digits decimal digits of precision (default 500).
asin
Returns the arcsine (inverse sine) of n radians.
atan
Returns the arctangent (inverse tangent) of n radians.
const_e
Returns e (Euler’s number) to d decimal digits of precision (default 500).
const_pi
Returns π (pi) to d decimal digits of precision (default 500).
cos
Returns the cosine of n radians.
deg_to_rad
Converts degrees to radians.
div
Returns the quotient a / b, with digits decimal digits of precision (default 500).
factorial
Returns the factorial of n, n!, computed via Γ(n+1).
ln
Returns the ln of n (ln(n)).
ln_factorial
Returns the natural logarithm of the factorial (ln(n!)).
log
Returns the base‑10 logarithm of n (log10(n)).
log2
Returns the base‑2 logarithm of n (log2(n)).
mul
Returns the product a * b, with digits decimal digits of precision (default 500).
pow
Returns the result of raising b to the power p (b^p).
rad_to_deg
Converts radians to degrees.
root
Returns the n‑th root of b (i.e., b^(1/n)) with d decimal digits of precision.
sin
Returns the sine of n radians.
sqrt
Returns the square root of n with d decimal digits of precision (default 500).
sub
Returns the difference a - b, with digits decimal digits of precision (default 500).
tan
Returns the tangent of n radians.