Aatch / ramp

RAMP - Rust Arithmetic in Multiple Precision
Apache License 2.0
261 stars 38 forks source link

0x10000000000000000.pow(3) is computed incorrectly #30

Closed huonw closed 9 years ago

huonw commented 9 years ago
extern crate ramp;
extern crate gmp;
use ramp::Int;
use gmp::mpz::Mpz;

macro_rules! eq {
    ($r: expr, $g: expr) => {
        assert_eq!($r.to_str_radix(16, false), $g.to_str_radix(16))
    }
}

fn parse(s: &str) -> (Int, Mpz) {
    (Int::from_str_radix(s, 16).unwrap(),
     Mpz::from_str_radix(s, 16).unwrap())
}
fn main() {
    let (ar, ag) = parse("10000000000000000");

    eq!(ar.pow(3),
        ag.pow(3));
}
thread '<main>' panicked at 'assertion failed: `(left == right)` (left: `"10000000000000000"`, right: `"1000000000000000000000000000000000000000000000000"`)', examples/isolated.rs:19

There has to be at least that many trailing zeros, presumably so that the lowest word is empty. And .pow(2) is computed correctly.