From nobody  Tue May 27 21:10:50 1997
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.5/8.8.5) id VAA21265;
          Tue, 27 May 1997 21:10:50 -0700 (PDT)
Message-Id: <199705280410.VAA21265@hub.freebsd.org>
Date: Tue, 27 May 1997 21:10:50 -0700 (PDT)
From: Tim.Brown@ctg.com
To: freebsd-gnats-submit@freebsd.org
Subject: FPE error in "normal" math code
X-Send-Pr-Version: www-1.0

>Number:         3700
>Category:       misc
>Synopsis:       FPE error in "normal" math code
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue May 27 21:20:01 PDT 1997
>Closed-Date:    Fri Feb 6 14:43:16 MET 1998
>Last-Modified:  Fri Feb  6 14:51:27 MET 1998
>Originator:     Tim Brown
>Release:        2.2.1
>Organization:
>Environment:
2.2.1-RELEASE (generalized, cannot paste)
>Description:
This line causes a SIGFPE:

x = (1900 - 100) / 8;

This works fine by itself.  In the program however it causes a SIGFPE.
All I know is that the source is old, Galactic Bloodshed source) and it requires -D_ANSI_SOURCE just to compile.  I am stumped.

Other info:  This line will also cause a SIGFPE:

return -216 + 5 * -1315 * 40 / (40 * -1221111);

Makes no sense becasue the code runs fine on older FreeBSD and most other Unixes (AIX, SunOS, Irix, ISC etc)

>How-To-Repeat:
Not sure
>Fix:
In the second case above,  I noticed that the following is being rounded to zero: 40 * -.00112334.  I simply trapped for this and added .0001, an incorrect solution.  Question is, why is it happening at all?

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: cracauer 
State-Changed-When: Fri Feb 6 14:43:16 MET 1998 
State-Changed-Why:  
I'm not able to reproduce the problem (on 2.2.2). The test program 
below runs just fine. To further investigate the problem, we would 
need a complete runnable program, so that type declarations aren't 
ommited. 


#define _ANSI_SOURCE 

#include <stdio.h> 
#include <math.h> 

double testfunc1() 
{ 
return -216 + 5 * -1315 * 40 / (40 * -1221111); 
} 

double testfunc2() 
{ 
return -216.0 + 5.0 * -1315.0 * 40.0 / (40.0 * -1221111.0); 
} 

int main() 
{ 
{ 
double foo; 
double bar; 
double baz; 

foo = 40.0; 
bar = -.00112334; 
baz = foo * bar; 

printf("%g (%g * %g)n",baz,foo,bar); 
} 

printf("%gn",testfunc1()); 
printf("%gn",testfunc2()); 

return 0; 
} 
>Unformatted:
