pub enum FastRational {
Small {
num: i64,
den: i64,
},
Big(Box<BigRational>),
}Expand description
A rational number that uses i64/i64 for small values and falls back to BigRational.
Over 95% of Simplex operations stay in the small path, avoiding heap allocation.
Variants§
Small
Small representation: num / den where den > 0 and gcd(|num|, den) == 1.
Fields
Big(Box<BigRational>)
Big representation: heap-allocated arbitrary-precision rational.
Implementations§
Source§impl FastRational
impl FastRational
Sourcepub fn new_small(num: i64, den: i64) -> Self
pub fn new_small(num: i64, den: i64) -> Self
Create a new Small rational, normalizing sign and reducing to lowest terms.
§Panics
Panics (debug-only) if den == 0. In release builds, division by zero
is undefined and will produce garbage.
Sourcepub fn from_big(br: BigRational) -> Self
pub fn from_big(br: BigRational) -> Self
Create a FastRational from a BigRational, demoting to Small if it fits.
Sourcepub fn to_big_rational(&self) -> BigRational
pub fn to_big_rational(&self) -> BigRational
Convert to BigRational.
Sourcepub fn recip(&self) -> Option<Self>
pub fn recip(&self) -> Option<Self>
Return the reciprocal (1/self). Returns None if self is zero.
Sourcepub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Check if this rational is an integer (denominator == 1).
Sourcepub fn from_big_ref(br: &BigRational) -> Self
pub fn from_big_ref(br: &BigRational) -> Self
Create a FastRational from a BigRational reference.
Sourcepub fn from_bigint(bi: &BigInt) -> Self
pub fn from_bigint(bi: &BigInt) -> Self
Create a FastRational representing an integer from a BigInt.
Source§impl FastRational
impl FastRational
Sourcepub fn from_integer(n: BigInt) -> Self
pub fn from_integer(n: BigInt) -> Self
Create a FastRational from an integer.
Trait Implementations§
Source§impl Add<&FastRational> for &FastRational
impl Add<&FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
+ operator.Source§impl Add<&FastRational> for FastRational
impl Add<&FastRational> for FastRational
Source§type Output = FastRational
type Output = FastRational
+ operator.Source§impl Add<FastRational> for &FastRational
impl Add<FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
+ operator.Source§impl Add for FastRational
impl Add for FastRational
Source§type Output = FastRational
type Output = FastRational
+ operator.Source§impl AddAssign<&FastRational> for FastRational
impl AddAssign<&FastRational> for FastRational
Source§fn add_assign(&mut self, rhs: &FastRational)
fn add_assign(&mut self, rhs: &FastRational)
+= operation. Read moreSource§impl AddAssign for FastRational
impl AddAssign for FastRational
Source§fn add_assign(&mut self, rhs: FastRational)
fn add_assign(&mut self, rhs: FastRational)
+= operation. Read moreSource§impl Clone for FastRational
impl Clone for FastRational
Source§fn clone(&self) -> FastRational
fn clone(&self) -> FastRational
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FastRational
impl Debug for FastRational
Source§impl Display for FastRational
impl Display for FastRational
Source§impl Div<&FastRational> for &FastRational
impl Div<&FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
/ operator.Source§impl Div<&FastRational> for FastRational
impl Div<&FastRational> for FastRational
Source§type Output = FastRational
type Output = FastRational
/ operator.Source§impl Div<FastRational> for &FastRational
impl Div<FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
/ operator.Source§impl Div for FastRational
impl Div for FastRational
Source§fn div(self, rhs: FastRational) -> Self::Output
fn div(self, rhs: FastRational) -> Self::Output
Source§type Output = FastRational
type Output = FastRational
/ operator.Source§impl DivAssign<&FastRational> for FastRational
impl DivAssign<&FastRational> for FastRational
Source§fn div_assign(&mut self, rhs: &FastRational)
fn div_assign(&mut self, rhs: &FastRational)
/= operation. Read moreSource§impl DivAssign for FastRational
impl DivAssign for FastRational
Source§fn div_assign(&mut self, rhs: FastRational)
fn div_assign(&mut self, rhs: FastRational)
/= operation. Read moreSource§impl From<&Ratio<BigInt>> for FastRational
impl From<&Ratio<BigInt>> for FastRational
Source§fn from(br: &BigRational) -> Self
fn from(br: &BigRational) -> Self
Source§impl From<BigInt> for FastRational
impl From<BigInt> for FastRational
Source§impl From<Ratio<BigInt>> for FastRational
impl From<Ratio<BigInt>> for FastRational
Source§fn from(br: BigRational) -> Self
fn from(br: BigRational) -> Self
Source§impl From<i64> for FastRational
impl From<i64> for FastRational
Source§impl Hash for FastRational
impl Hash for FastRational
Source§impl Mul<&FastRational> for &FastRational
impl Mul<&FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
* operator.Source§impl Mul<&FastRational> for FastRational
impl Mul<&FastRational> for FastRational
Source§type Output = FastRational
type Output = FastRational
* operator.Source§impl Mul<FastRational> for &FastRational
impl Mul<FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
* operator.Source§impl Mul for FastRational
impl Mul for FastRational
Source§type Output = FastRational
type Output = FastRational
* operator.Source§impl MulAssign<&FastRational> for FastRational
impl MulAssign<&FastRational> for FastRational
Source§fn mul_assign(&mut self, rhs: &FastRational)
fn mul_assign(&mut self, rhs: &FastRational)
*= operation. Read moreSource§impl MulAssign for FastRational
impl MulAssign for FastRational
Source§fn mul_assign(&mut self, rhs: FastRational)
fn mul_assign(&mut self, rhs: FastRational)
*= operation. Read moreSource§impl Neg for &FastRational
impl Neg for &FastRational
Source§impl Neg for FastRational
impl Neg for FastRational
Source§impl Num for FastRational
impl Num for FastRational
type FromStrRadixErr = String
Source§fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
fn from_str_radix(str: &str, radix: u32) -> Result<Self, Self::FromStrRadixErr>
2..=36). Read moreSource§impl One for FastRational
impl One for FastRational
Source§impl Ord for FastRational
impl Ord for FastRational
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for FastRational
impl PartialEq for FastRational
Source§impl PartialOrd for FastRational
impl PartialOrd for FastRational
Source§impl Rem<&FastRational> for &FastRational
impl Rem<&FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
% operator.Source§impl Rem for FastRational
impl Rem for FastRational
Source§fn rem(self, rhs: FastRational) -> Self::Output
fn rem(self, rhs: FastRational) -> Self::Output
Remainder for rationals: a % b = a - b * floor(a/b).
For non-zero b, this returns a value in [0, |b|).
Source§type Output = FastRational
type Output = FastRational
% operator.Source§impl RemAssign for FastRational
impl RemAssign for FastRational
Source§fn rem_assign(&mut self, rhs: FastRational)
fn rem_assign(&mut self, rhs: FastRational)
%= operation. Read moreSource§impl Signed for FastRational
impl Signed for FastRational
Source§fn is_positive(&self) -> bool
fn is_positive(&self) -> bool
Source§fn is_negative(&self) -> bool
fn is_negative(&self) -> bool
Source§impl Sub<&FastRational> for &FastRational
impl Sub<&FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
- operator.Source§impl Sub<&FastRational> for FastRational
impl Sub<&FastRational> for FastRational
Source§type Output = FastRational
type Output = FastRational
- operator.Source§impl Sub<FastRational> for &FastRational
impl Sub<FastRational> for &FastRational
Source§type Output = FastRational
type Output = FastRational
- operator.Source§impl Sub for FastRational
impl Sub for FastRational
Source§type Output = FastRational
type Output = FastRational
- operator.Source§impl SubAssign<&FastRational> for FastRational
impl SubAssign<&FastRational> for FastRational
Source§fn sub_assign(&mut self, rhs: &FastRational)
fn sub_assign(&mut self, rhs: &FastRational)
-= operation. Read moreSource§impl SubAssign for FastRational
impl SubAssign for FastRational
Source§fn sub_assign(&mut self, rhs: FastRational)
fn sub_assign(&mut self, rhs: FastRational)
-= operation. Read more