From nobody  Fri Aug 21 11:03:19 1998
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.8/8.8.8) id LAA09295;
          Fri, 21 Aug 1998 11:03:19 -0700 (PDT)
          (envelope-from nobody)
Message-Id: <199808211803.LAA09295@hub.freebsd.org>
Date: Fri, 21 Aug 1998 11:03:19 -0700 (PDT)
From: sas@schell.de
To: freebsd-gnats-submit@freebsd.org
Subject: fp exception in 1.0 / (double + 1.0)
X-Send-Pr-Version: www-1.0

>Number:         7707
>Category:       kern
>Synopsis:       fp exception in 1.0 / (double + 1.0)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 21 11:10:01 PDT 1998
>Closed-Date:    Mon Sep 7 15:47:34 MEST 1998
>Last-Modified:  Mon Sep  7 15:54:39 MEST 1998
>Originator:     Sascha
>Release:        -current (some days old)
>Organization:
>Environment:
FreeBSD guerilla.foo.bar 3.0-CURRENT FreeBSD 3.0-CURRENT #4: Sun Aug 16 17:00:38 CEST 1998     root@guerilla.foo.bar:/usr/src/sys/compile/SAS1  i386
>Description:
A floating point exception will happen under special circumstances.

This problem hit me while trying out amp (it's some code from init_layer3() of layer3.c).

I don't see any bad code here, so it should really work. Just recompiled libm,
but that didn't help...
>How-To-Repeat:
main() {
	double d, t;
	
	d = tan( (double) 9 * M_PI / 12.0); /* this is about 1 */
	t = 1.0 / (1.0 + d); /* fp exception here */
}
>Fix:

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: thepish 
State-Changed-When: Sat Aug 29 21:54:32 PDT 1998 
State-Changed-Why:  
User feedback requested. Cannot reproduce on kickme with supplied example (runs fine) 
State-Changed-From-To: analyzed->closed 
State-Changed-By: cracauer 
State-Changed-When: Mon Sep 7 15:47:34 MEST 1998 
State-Changed-Why:  
Can't reproduce problem, either, your supplied test cases runs fine. 

The supplied program as such didn't compile, you don't include 
<math.h> and therefore don't have M_PI in scope. 

Just a guess: You compiled the program that actually failed without 
<math.h>, getting the value of pi somewhere else. That means that the 
tan() function return value defaults to a return-type of int. Since it 
actually returns a double, a junk double value that the compiler 
doesn't know of is pushed on top of the FPU stack. If the stack is 
near full because of previous regular floating point operations, 
you'll get an "invalid operation" floating point exception caused by a 
stack overflow. 

The is Bruce Evan's cannonical example why throwing FPEs by default is 
good, since you FPU stack would be toast otherwise. 

Please give me feedback if that analysis could be correct. 

Martin 
>Unformatted:
