rust-num / num-rational

Generic Rational numbers for Rust
Apache License 2.0
144 stars 51 forks source link

BigInt properly recognized #96

Open janus opened 3 years ago

janus commented 3 years ago

What could be causing the below? I have not been able to figure if there is another crate with same name.

use num_bigint::{BigUint, BigInt}; use num_rational::BigRational;

   |
38 |     let f = BigRational::new(BigInt::one(), BigInt::one());
   |                                             ^^^^^^^^^^^^^ expected struct `num_bigint::bigint::BigInt`, found struct `BigInt`
   |
   = note: perhaps two different versions of crate `num_bigint` are being used?
cuviper commented 3 years ago

It means your num_bigint dependency version doesn't match the indirect dependency used by your version of num_rational. The compiler treats different versions as completely distinct types. You can run cargo tree to see which is which.

You should make sure both dependencies are updated to their latest version in your Cargo.toml.

janus commented 3 years ago

@cuviper Thanks so much for this command cargo tree. But is there a way to know the number of bits in BigRational?

cuviper commented 3 years ago

You can call .numer() and .denom() to access each BigInt part, then call .bits() on those.