pub fn from_float<T: FloatCore>(f: T) -> Option<BigRational> {
        if !f.is_finite() {
            return None;
        }
        let (mantissa, exponent, sign) = f.integer_decode();
        let bigint_sign = if sign == 1 { Sign::Plus } else { Sign::Minus };
        if exponent < 0 {
            let one: BigInt = One::one();
            let denom: BigInt = one << ((-exponent) as usize);
            let numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
            Some(Ratio::new(BigInt::from_biguint(bigint_sign, numer), denom))
        } else {
            let mut numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
            numer <<= exponent as usize;
            Some(Ratio::from_integer(BigInt::from_biguint(
                bigint_sign,
                numer,
            )))
        }
    }
/// Converts a float into a rational number.
Converts a float into a rational number.
Converts a float into a rational number .
pub fn from_float<T: FloatCore>(f: T) -> Option<BigRational> {
        if !f.is_finite() {
            return None;
        }
        let (mantissa, exponent, sign) = f.integer_decode();
        let bigint_sign = if sign == 1 { Sign::Plus } else { Sign::Minus };
        if exponent < 0 {
            let one: BigInt = One::one();
            let denom: BigInt = one << ((-exponent) as usize);
            let numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
            Some(Ratio::new(BigInt::from_biguint(bigint_sign, numer), denom))
        } else {
            let mut numer: BigUint = FromPrimitive::from_u64(mantissa).unwrap();
            numer <<= exponent as usize;
            Some(Ratio::from_integer(BigInt::from_biguint(
                bigint_sign,
                numer,
            )))
        }
    }
pub fn from_float < T : FloatCore > ( f : T ) -> Option < BigRational > { if ! f . is_finite ( ) { return None ; } let ( mantissa , exponent , sign ) = f . integer_decode ( ) ; let bigint_sign = if sign == 1 { Sign :: Plus } else { Sign :: Minus } ; if exponent < 0 { let one : BigInt = One :: one ( ) ; let denom : BigInt = one << ( ( - exponent ) as usize ) ; let numer : BigUint = FromPrimitive :: from_u64 ( mantissa ) . unwrap ( ) ; Some ( Ratio :: new ( BigInt :: from_biguint ( bigint_sign , numer ) , denom ) ) } else { let mut numer : BigUint = FromPrimitive :: from_u64 ( mantissa ) . unwrap ( ) ; numer <<= exponent as usize ; Some ( Ratio :: from_integer ( BigInt :: from_biguint ( bigint_sign , numer , ) ) ) } }
Converts a float into a rational number.
Converts a float into a rational number .
f
T
f
T