delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/12/25/01:17:03

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00
X-Spam-Check-By: sourceware.org
Message-ID: <724619.16892.qm@web25501.mail.ukl.yahoo.com>
Date: Fri, 25 Dec 2009 06:16:47 +0000 (GMT)
From: Marco Atzeri <marco_atzeri AT yahoo DOT it>
Subject: R: floating-point math problem in Cygwin 1.7?
To: cygwin AT cygwin DOT com, Linh Phan <linhphan AT usc DOT edu>
In-Reply-To: <200912242119.nBOLJCr7019530@aludra.usc.edu>
MIME-Version: 1.0
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT 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

--- Gio 24/12/09, Linh Phan  ha scritto:

> Hi,
>=20
> =C2=A0 I have wondering why when I do floating-point math
> in Cygwin 1.7, Cygwin does not output the "correct" result,
> eg:
>=20
> main () {
> =C2=A0 double qcb[4] =3D {0.41585680180318363,
> 0.70823637211274604, 0.089200955545759006,=C2=A0
> -0.56347808399291521};
> =C2=A0 double qba[4] =3D {0.09648538897087118,
> -0.37032037362514358,
> 0.89403246842889339,=C2=A0=C2=A0=C2=A00.23293633462432001};
> =C2=A0 double qca[4];
>=20
> =C2=A0 qca[0]=3D qcb[3]*qba[0] + qcb[2]*qba[1] -
> qcb[1]*qba[2] + qcb[0]*qba[3];
> =C2=A0 qca[1]=3D -qcb[2]*qba[0] + qcb[3]*qba[1] +
> qcb[0]*qba[2] + qcb[1]*qba[3];
> =C2=A0 qca[2]=3D qcb[1]*qba[0] - qcb[0]*qba[1] +
> qcb[3]*qba[2] + qcb[2]*qba[3];
> =C2=A0 qca[3]=3D -qcb[0]*qba[0] - qcb[1]*qba[1] -
> qcb[2]*qba[2] + qcb[3]*qba[3];
>=20
> =C2=A0 // I am expecting the result to be:
>=20
> =C2=A0 printf("qca =3D [-0.623718486146499718,
> 0.736824293298044886, -0.260654850643024127,
> 0.011147182658310384] CORRECT (LINUX/SOLARIS)\n");
>=20
> =C2=A0 // I get the above result on both Linux/Solaris AND
> even when running under Cygwin's gdb and using gdb's printf
>=20
> =C2=A0 // but when I compile and run on cygwin, I get the
> wrong result:

s/wrong/different

> =C2=A0 printf("qca =3D [%.18f, %.18f, %.18f, %.18f] NOT
> CORRECT (CYGWIN)\n",qca[0],qca[1],qca[2],qca[3]);
> }
>=20
> Here is the output when I compiled and run on cygwin:
>=20
> qca =3D [-0.623718486146499718, 0.736824293298044886,
> -0.260654850643024127, 0.011147182658310384] CORRECT
> (LINUX/SOLARIS)
> qca =3D [-0.623718486146499607, 0.736824293298044886,
> -0.260654850643024072, 0.011147182658310373] NOT CORRECT
> (CYGWIN)
>=20
> Here's the output when running under cygwin's gdb (it
> matches Linux/Solaris outputs but not cygwin=E2=80=99s output):
>=20
> (gdb) printf "%.18f\n", qcb[3]*qba[0] + qcb[2]*qba[1] -
> qcb[1]*qba[2] + qcb[0]*qba[3]
> -0.623718486146499718
> (gdb) printf "%.18f\n", -qcb[2]*qba[0] + qcb[3]*qba[1] +
> qcb[0]*qba[2] + qcb[1]*qba[3]
> 0.736824293298044886
> (gdb) printf "%.18f\n", qcb[1]*qba[0] - qcb[0]*qba[1] +
> qcb[3]*qba[2] + qcb[2]*qba[3]
> -0.260654850643024127
> (gdb) printf "%.18f\n", -qcb[0]*qba[0] - qcb[1]*qba[1] -
> qcb[2]*qba[2] + qcb[3]*qba[3]
> 0.011147182658310384
> (gdb)=20
>=20
> These errors accumulate and eventually builds up so much
> that the my simulation result is totally wrong when running
> under cygwin.
>=20
> Please help.=C2=A0=20

I will bet=20
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D323

see
http://hal.archives-ouvertes.fr/hal-00128124
for further detailed info on rounding

if so it is not a bug is a feature=20
:-)

by the way on (cygwin) octave that round as you expect I have
 printf("%.18g\n",qca)
-0.623718486146499718
0.736824293298044886
-0.260654850643024127
0.0111471826583103839



> Thanks,
>=20
> Linh
>=20

Marco





--
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