In the example you give, it seems that both programs have the same floating point numbers. They just print them in different ways. The easiest solution to this problem is to write your own floating point printing function. If you do not expect the output to be too pleasant, you can use the function here as a pseudo-code to write your word in C. It is not correctly rounded, but it works for what it is intended for (i.e., reproducible and readable outputs).
The deeper problem that you are facing is floating point calculations that give different results on different platforms. This is a result of the fact that C standards do not force compilers to implement the IEEE 754 floating point standard, in particular, which improves the accuracy of intermediate results. And this relative condescension of standard (s) C is caused, at least in part, by historical x86 floating point instructions, which makes it expensive to implement the exact semantics of IEEE 754.
On Linux, if you use GCC, try the -msse2 compilation option. EDIT: OP commented that -msse2 -mfpmath=sse worked for him. This makes GCC generate modern SSE2 instructions that give the exact IEEE 754 floating point semantics. If you use GCC on Windows, use the same option.
If you are using Visual C: Visual C uses a different trick to make historical floating point instructions conform to the IEEE 754 semantics: it reports that old 80-bit floating point hardware uses only as many important bits as IEEE 754 double precision. This gives you accurate double-precision modeling of numbers, with the exception of a few angular cases that you will not encounter. In this case, it would help (*) if your program only used double precision numbers (type C double ).
(*) The Visual C compiler could theoretically generate code that calculates exact arithmetic with one precision, rounding each intermediate result from double to one precision, but that would be expensive, and I doubt it is.
source share