Re: c vs java floating point errors under windows XP
From: Jack Klein (jackklein_at_spamcop.net)
Date: 06/12/04
- Next message: Michael Wojcik: "Re: which language?"
- Previous message: Ian Woods: "Re: Aspiring highest-order programmer"
- In reply to: valis: "c vs java floating point errors under windows XP"
- Next in thread: Michael N. Christoff: "Re: c vs java floating point errors under windows XP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 22:07:22 -0500
On 11 Jun 2004 11:50:27 -0700, howe.charles@mayo.edu (valis) wrote in
comp.programming:
> I have an application that requires between 10^12 and 10^15 iterations
> of a floating point calculation. The precision of the numbers must be
> at least 20 digits for the math to work out. I have written an
> algorithm in java and in C to accomplish this calculation. Under
> Linux, both algorithms appear to work fine, and the accumulated error
> does not impact on the outcome. However, in Windows, the java
> algorithm seems to run fine but the C calculation (compiled with gcc
> under MinGW) suffers from extreme error that renders the calculation
> completely useless. Can anyone explain to me what the difference might
> be between the java code (compiled under jdk1.3.1_03) and the C code
> in terms of the floating point calculations? Also, what is the
> difference between running the calculation on Linux vs WinXP? The
> reason I cannot simply use the java algorithm is that the large number
> of iterations takes several days in java, but only several hours in C.
>
> Thanx.
You left some important information out of your post.
In the first place, no native floating point format on x86 hardware
has 20 decimal digits of precision.
The second is the data type you are using. Are you using float,
double, or long double? If you are attempting to use long double,
MinGW is the wrong compiler to use, as would be Microsoft's Visual
C++.
MinGW uses the Microsoft default C library run time supplied with the
operating system. Microsoft long ago made a stupid marketing decision
that it was better to restrict long double in their 32 bit compilers
to the Intel 64 bit format (same as plain double) for "compatibility"
with implementations of Windows NT on other platforms.
You can see their web page about it at
http://support.microsoft.com/support/kb/articles/Q129/2/09.asp
Apparently there has never been enough complaint from their users to
make them change their minds, although it places their compiler at a
very serious disadvantage for many types of scientific and engineering
applications.
Since MinGW uses Microsoft's library, it too limits long double to 64
bits instead of using the Intel FPU 80 bit format.
In addition to the size, there is a bit in the Intel FPU control
hardware that forces it to truncate even internal calculations at 64
bits, rather than the default 80 bits, and that too can reduce the
accuracy of chained calculations.
Overall, if you want maximum floating point precision on Windows, you
need a compiler like Borland or a GCC port with its own libraries like
DJGPP or Cygwin, or some other compiler that does not deliberately
limit your ability to use the maximum precision built into the
hardware for bull*** marketing reasons.
-- Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html comp.lang.c++ http://www.parashift.com/c++-faq-lite/ alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html
- Next message: Michael Wojcik: "Re: which language?"
- Previous message: Ian Woods: "Re: Aspiring highest-order programmer"
- In reply to: valis: "c vs java floating point errors under windows XP"
- Next in thread: Michael N. Christoff: "Re: c vs java floating point errors under windows XP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]