Expand description

This crate provides representations of part of irrational numbers with following categories:

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 to num_complex::Complex. You probably want to enable the complex feature at the same time.
  • num-bigint: Enable using big integer as internal representations.

Re-exports

pub use cont_frac::simple::ContinuedFraction;
pub use cont_frac::simple::InfiniteContinuedFraction;
pub use cont_frac::general::GeneralContinuedFraction;
pub use quadratic::surd::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

Enums

Represents a number conversion with probably exact value.

Represents a possible error occured calling FromSqrt

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