Expand description
This crate provides representations of irrational numbers within following categories:
- Math constants (
pi
,e
, etc.)- Values and continued fraction representations
- Quadratic Numbers
- Continued Fraction
- Simple continued fraction: ContinuedFraction, InfiniteContinuedFraction
- General continued fraction: GeneralContinuedFraction
- Transcendental functions represented in continued fractions
It’s based on the num
creates.
§Examples
use num_irrational::{FromSqrt, QuadraticSurd};
let sq2 = QuadraticSurd::from_sqrt(2i32).unwrap();
println!("Square root of 2: {}", sq2); // √2
use num_irrational::Computable;
let sq2_approx = sq2.approximated(&100).value();
println!("Rational approximation with denominator under 100: {}", sq2_approx); // 99/70
use core::convert::TryFrom;
use num_irrational::ContinuedFraction;
// let sq2_fraction = ContinuedFraction::from(sq2); // only if feature `complex` is disabled
let sq2_fraction = ContinuedFraction::try_from(sq2).unwrap();
println!("Continued Fraction: {}", sq2_fraction); // [1; (2)]
§Optional Features
complex
: Enable negative square root base support for QuadraticSurd. Note that this flag might change some behavior of the operators on QuadraticSurd.num-complex
: Enable converting QuadraticSurd tonum_complex::Complex
. You probably want to enable thecomplex
feature at the same time.num-bigint
: Enable using big integers as the internal representation.
Re-exports§
pub use cont_frac::ContinuedFraction;
pub use cont_frac::GeneralContinuedFraction;
pub use cont_frac::InfiniteContinuedFraction;
pub use quadratic::QuadraticInt;
pub use quadratic::QuadraticSurd;
pub use quadratic::GaussianInt;
Modules§
- cont_
frac - Data structures and algorithms implementations related to regular and generalized continued fraction
- quadratic
- Data structures and algorithms implementations related to quadratic numbers (roots of quadratic equation).
- symbols
- Predefined irrational math constants
Structs§
- From
Sqrt Error - Represents a possible error occured calling FromSqrt
Enums§
- Approximation
- Represents a number conversion with probably exact value.
- Sqrt
Error Kind - Types of FromSqrt errors
Traits§
- Computable
- This trait represents a real number that is computable. See Wiki
- From
Sqrt - Create a number instance from the square root of another number.
- With
Signed - Represents a number type with corresponding signed version
- With
Unsigned - Represents a number type with corresponding unsigned version
Type Aliases§
- BigQuadratic
- QuadraticSurd with big integers
- BigQuadratic
Int - QuadraticInt with big integers
- Quadratic32
- QuadraticSurd with 32-bit integers
- Quadratic64
- QuadraticSurd with 64-bit integers
- Quadratic
Int32 - QuadraticInt with 32-bit integers
- Quadratic
Int64 - QuadraticInt with 64-bit integers