2

I'm working with a raspberry 2 running Arch

Linux a4h-rpi2-arch 4.1.12-1-ARCH #1 SMP PREEMPT Tue Oct 27 19:16:16 MDT 2015 armv7l GNU/Linux

I got some problem to display float on cout using c++ streams. Here is a simple main :

#include <iostream>

using namespace std;



int main() {

float f;
f = 9.87654321f;
cout << f << endl;
f = 987.654321f;
cout << f << endl;
f = 987654.321f;
cout << f << endl;
f = 9876543.21f;
cout << f << endl;
f = 0.0000987654321f;
cout << f << endl;
return 0;
}

i cross compiled it with raspberry toolchain :

arm-bcm2708-linux-gnueabi-g++ -o /tmp/test_stream /tmp/test.cpp

Here is result :

test_stream
0
0
0
0
0

Now if I compile it with

arm-bcm2708hardfp-linux-gnueabi-g++ -o /tmp/test_stream /tmp/test.cpp

I get correct results :

test_stream
9.87654
987.654
987654
9.87654e+06
9.87654e-05

In first case I'm only using software to perform float calculations. I shouldn't have any differences in result between 2 toolchain? Only compute time should be better using hard float hw unit?

lah

1

In first case I'm only using software to perform float calculations.

No; since the executable is dynamically linked to the system library on a platform with hardware floating point support, there is no facility to perform such calculations with software.

At least, that's my guess. I think it will turn out differently if you compile a static binary.

Put another way, this:

arm-bcm2708-linux-gnueabi-g++

Is evidently the wrong compiler for the platform.

  • Just for testing I compiled it statically and I got correct results. So I changed toolchain. – rem Nov 16 '15 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.