Ken Chu
|
Double/float accuracy in QNX 7.1
|
Ken Chu
08/12/2021 11:36 PM
post121558
|
Double/float accuracy in QNX 7.1
Hi,
I am seeing an issue with accuracy of float/double in QNX 7.1.
For example, with this code:
#include <stdio.h>
int main(int argc, char** argv)
{
double d;
d = 1234567890123.0;
printf("%lf\n", d);
d = 12345678901234.0;
printf("%lf\n", d);
d = 123456789012345.0;
printf("%lf\n", d);
d = 1234567890123456.0;
printf("%lf\n", d);
d = 12345678901234567.0;
printf("%lf\n", d);
d = 123456789012345678.0;
printf("%lf\n", d);
d = 1234567890123456789.0;
printf("%lf\n", d);
d = 12345678901234567890.0;
printf("%lf\n", d);
d = 1e13;
printf("%lf\n", d);
d = 1e14;
printf("%lf\n", d);
d = 1e15;
printf("%lf\n", d);
d = 1e16;
printf("%lf\n", d);
d = 1e17;
printf("%lf\n", d);
d = 1e18;
printf("%lf\n", d);
d = 1e19;
printf("%lf\n", d);
d = 1e20;
printf("%lf\n", d);
return 0;
}
When I run it on a Ubuntu 18.04 PC, I get this output:
1234567890123.000000
12345678901234.000000
123456789012345.000000
1234567890123456.000000
12345678901234568.000000
123456789012345680.000000
1234567890123456768.000000
12345678901234567168.000000
10000000000000.000000
100000000000000.000000
1000000000000000.000000
10000000000000000.000000
100000000000000000.000000
1000000000000000000.000000
10000000000000000000.000000
100000000000000000000.000000
When I run it in QNX 7.1 x86 QEMU, I get this output:
1234567890123.000000
12345678901234.000000
123456789012345.000000
1234567890123456.000000
12345678901234567.999900
123456789012345679.999900
1234567890123456767.999900
12345678901234567167.999900
10000000000000.000000
100000000000000.000000
1000000000000000.000000
9999999999999999.999900
99999999999999999.999900
999999999999999999.999900
9999999999999999999.999900
99999999999999999999.000000
If my understanding is correct, the accuracy of double is 15 digits (same on QNX and Ubuntu PC). However, as shown in
above example, the first 15 digits are not right when float is 1e16 and above.
Is there a configuration or compiler option to allow the output be more like on the Ubuntu PC? We ran into this issue
when running a unit test for an open source package. It used 1e21 in the test case which causes a test failure in QNX 7
.1.
Thanks.
|
|
|