delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/24/20:09:52

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Eric Backus <eric_backus AT agilent DOT com>
Subject: Re: floating-point math problem in Cygwin 1.7?
Date: Fri, 25 Dec 2009 01:09:14 +0000 (UTC)
Lines: 43
Message-ID: <loom.20091225T014846-910@post.gmane.org>
References: <200912242119 DOT nBOLJCr7019530 AT aludra DOT usc DOT edu>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Linh Phan <linhphan <at> usc.edu> 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.


-- 
Eric



--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019