This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Strange g+ 3.1.1 double behavior
- From: Nathan Sidwell <nathan at acm dot org>
- To: Gunther Weber <weber at informatik dot uni-kl dot de>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 05 Aug 2002 15:15:57 +0100
- Subject: Re: Strange g+ 3.1.1 double behavior
- References: <3D4E8656.6030402@informatik.uni-kl.de>
- Reply-to: nathan at compsci dot bristol dot ac dot uk
Gunther Weber wrote:
> while searching for a problem in one of my programs I ran across this
> strange gcc 3.1.1 beahvior:
> std::cout << torus(0.0,0.0,10.0) - torus(0.0,0.0,10.0) << std::endl;
> 3.85469e-13
> All this on a Celeron system running RedHat 7.3. Does anyone what could
> be causing this? I would expect that both function calls with identical
> arguments would result in the same double value and thus in the programm
Not necesarily. floating point calculations can be performed at a
higher precision, and this happens on i86 hardware. IIRC the return value
will be in an i86 floating point register at 80 bits precision. One
return value must be stored on the stack (in a 64 bit double, hence
rounded), the other return value need not be, so is not rounded. The
result you see is the rounding error. This spilling of intermediates
at a lower precision is a quality of implementation thing.
-mfloat-store might help you here.
nathan
--
Dr Nathan Sidwell :: Computer Science Department :: Bristol University
The voices in my head told me to say this
nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk