Weird results from math function

This code does not produce the output that I expect. I was writing a routine to convert an extended 80-bits floating point (in order to read AIFF files; the comments refer to the original expressions) and found that it yielded a very odd result.

fn main() {
    let hm = 2890137600.0_f64; // f64::from(hi_mant);
    let hme = -16_i32; // expon - 16383 - 31;
    let lm = 0.0_f64; // f64::from(lo_mant);
    let lme = -48_i32; // hme - 32;
    println!("{} * 2 ^ {} + {} * 2 ^ {}", hm, hme, lm, lme);
    let h = hm.powi(hme); // powf yields the same result
    let l = lm.powi(lme);
    println!("= {} + {}", h, l);
    println!("= {}", h + l);
}

When I run the program, I see this output

2890137600 * 2 ^ -16 + 0 * 2 ^ -48
= 0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004219914759992248 + inf
= inf

while the actual answer should be 44100. When I feed the same expression in my rust expression calculator, it does yield the correct result, so it's not as if it's totally impossible. Am I overlooking something totally obvious?

Edit: platform is OSX 10.11, rust 1.6

But those aren't the same thing; you aren't calculating 0 * 2^-48, you're calculating 0^-48. Same for the LHS.

1 Like

Bloody hell. That was dumb.

Thanks!