[Solved] Weird float behaviour on arm


#1

When compiling the following on my raspberry pi v2:

fn main() {
    let expected = 0.09375f64;
    println!("EXPECTED: {:?}", expected);
}

the compiled program prints: EXPECTED: 0. Can someone explain to me why?

The architecture is:

$ uname -m
armv7l

… with further exploration:

fn main() {
    let expected = 100f32;
    println!("EXPECTED: {}", expected);

    let expected = 100f64;
    println!("EXPECTED: {}", expected);

    let expected = 100.0;
    println!("EXPECTED: {}", expected);
}

prints:

EXPECTED: 0.00000000000000000000000000000000000000000014
EXPECTED: 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000494
EXPECTED: 0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000494

Is there something about the arm architecture that does not understand f32 and f64 types?


#2

I think this is compiler bug


#3

@Dushistov I think you’re right. Updating to the latest stable compiler seems to have solved this problem, thanks!


#4

You probably used rust 1.13, right?

See:

Under “Other notable changes” you find:

1.13 contains a serious bug in code generation for ARM targets using hardware floats (which is most ARM targets). ARM targets in Rust are presently in our 2nd support tier, so this bug was not determined to block the release. Because 1.13 contains a security update, users that must target ARM are encouraged to use the 1.14 betas, which will soon get a fix for ARM.

From the linked bug report, it sounds like a rustc compiled for ARM was unable to correctly parse float constants.


#5

Thanks @exoticorn for finding that out. I don’t keep my pi’s rust compiler up to date.