This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: floating-point math problem in Cygwin 1.7?

Linh Phan <linhphan <at>> writes:

>   I have wondering why when I do floating-point math in Cygwin 1.7, Cygwin 
does not output the "correct"
> result, eg:
> qca = [-0.623718486146499718, 0.736824293298044886, -0.260654850643024127,
> 0.011147182658310384] CORRECT (LINUX/SOLARIS)
> qca = [-0.623718486146499607, 0.736824293298044886, -0.260654850643024072,
> 0.011147182658310373] NOT CORRECT (CYGWIN)

These variables are declared "double".  On cygwin, and Linux, and probably 
Solaris, that means they are 64-bit IEEE floating-point values, with 53 bits 
of mantissa.  That gives the values only about 16 digits of precision, and the 
values you show do seem to match for roughly that many digits.  So, I think 
technically nothing is very wrong here.

Why are the values different?  The root of this is the x86 floating-point 
processor, which internally does calculations with 80-bit floating-point 
registers (with 64-bit mantissa).  Depending on when and how these 80-bit 
values are converted back to 64-bit doubles and stored in memory, you can get 
slightly different answers.

You might try looking at the command-line options you're giving to the 
compiler.  There might be some setting which allows the processor to keep 
values in the 80-bit floating-point registers longer, thus keeping more 
accuracy.  You might try "-ffast-math" and see if that helps.  Maybe even just 
turning on optimization ("-O2" or "-O3") might help.  You might try 
using "long double" instead of "double", but be careful because I think Cygwin 
still doesn't have full support for long double.

> These errors accumulate and eventually builds up so much that the my 
simulation result is totally wrong
> when running under cygwin.

It is possible that this points to problems with your simulation itself, if it 
is this sensitive to accumulated errors that are this small.


Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]