Crate num_irrational
source · [−]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;
Modules
Data structures and algorithms implementations related to regular and generalized continued fraction
Data structures and algorithms implementations related to quadratic numbers (roots of quadratic equation).
Predefined irrational math constants
Structs
Represents a possible error occured calling FromSqrt
Enums
Represents a number conversion with probably exact value.
Types of FromSqrt errors
Traits
This trait represents a real number that is computable. See Wiki
Create a number instance from the square root of another number.
Represents a number type with corresponding signed version
Represents a number type with corresponding unsigned version
Type Definitions
QuadraticSurd with big integers
QuadraticInt with big integers
QuadraticSurd with 32-bit integers
QuadraticSurd with 64-bit integers
QuadraticInt with 32-bit integers
QuadraticInt with 64-bit integers