num-rational icon indicating copy to clipboard operation
num-rational copied to clipboard

BigInt properly recognized

Open janus opened this issue 4 years ago • 3 comments

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?

janus avatar Jun 09 '21 12:06 janus

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.

cuviper avatar Jun 10 '21 06:06 cuviper

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

janus avatar Aug 11 '21 11:08 janus

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

cuviper avatar Aug 17 '21 23:08 cuviper