Crate num_irrational

Source
Expand description

This crate provides representations of irrational numbers within 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 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§

FromSqrtError
Represents a possible error occured calling FromSqrt

Enums§

Approximation
Represents a number conversion with probably exact value.
SqrtErrorKind
Types of FromSqrt errors

Traits§

Computable
This trait represents a real number that is computable. See Wiki
FromSqrt
Create a number instance from the square root of another number.
WithSigned
Represents a number type with corresponding signed version
WithUnsigned
Represents a number type with corresponding unsigned version

Type Aliases§

BigQuadratic
QuadraticSurd with big integers
BigQuadraticInt
QuadraticInt with big integers
Quadratic32
QuadraticSurd with 32-bit integers
Quadratic64
QuadraticSurd with 64-bit integers
QuadraticInt32
QuadraticInt with 32-bit integers
QuadraticInt64
QuadraticInt with 64-bit integers