Bug 69496 - strange floating point exceptions in trivial C programs
Summary: strange floating point exceptions in trivial C programs
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 7.1
Hardware: alpha
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-07-22 20:30 UTC by Need Real Name
Modified: 2007-04-18 16:44 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-07-22 21:07:45 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Need Real Name 2002-07-22 20:30:26 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) Gecko/20020618

Description of problem:
It is possible to write a trivial C program which causes a floating point
exception using one summation.

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Compile and link these programs with "gcc -o foo foo.c".  I've tried many other
optimization and debug settings, with no change in results.

This C code works correctly:
#include <stdio.h>
int main(void)
  printf("sum=%g\n", 1.21678e-308 + 1.07381e-308);
  return 0;

This C code dies with a floating point exception:
#include <stdio.h>
int main(void)
  double hi, lo, sum;
  hi = 1.21678e-308;
  lo = 1.07381e-308;
  sum = (hi + lo);            /* Produces bad result. */
  printf( "sum=%g\n", sum);   /* Dies here. */
  return 0;

Actual Results:  The first program works correctly.  The second does not.

Expected Results:  Both should have worked correctly. =-)

Additional info:

For both of these programs, compiling with Compaq's ccc produces underflow
warnings but the executable works correctly (no fp exceptions and prints the
expected "sum=2.29059e-308".

gcc2.96 fails, as does gcc3.1 (built from sources).

We've messed with this on 3 Alpha machines.  Two have dual 667MHz 21264 cpus
(DS-20 clones from Microway, 4MB cache), and one is a single cpu Compaq ES-40
(8MB cache).

We've fought with and tried to work around this for quite a while, and have
finally distilled it to this form.  Any help (workarounds, bug fixes, etc) would
be greatly appreciated, as this has cost us a lot of time.  I'd be happy to
provide assembly dumps or run experiments as needed.

Comment 1 Jakub Jelinek 2002-07-22 21:07:41 UTC
Have you tried -mieee?

Comment 2 Need Real Name 2002-07-22 21:19:27 UTC
Nope, we haven't.  Things appear work properly when we do.  I apologize for
wasting your bug time on us lusers.  I only wish we had wasted your time in
January instead of waiting until July. ;-)

Note You need to log in before you can comment on or make changes to this bug.