From nobody@FreeBSD.org  Wed Jul  9 20:09:37 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 33AF5106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  9 Jul 2008 20:09:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1C0A98FC12
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  9 Jul 2008 20:09:37 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m69K9aGL063904
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 9 Jul 2008 20:09:36 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m69K9aHm063903;
	Wed, 9 Jul 2008 20:09:36 GMT
	(envelope-from nobody)
Message-Id: <200807092009.m69K9aHm063903@www.freebsd.org>
Date: Wed, 9 Jul 2008 20:09:36 GMT
From: "Pedro F. Giffuni" <pfgshield-freebsd@yahoo.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: /usr/bin/awk fails mawk's FPE test
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         125449
>Category:       bin
>Synopsis:       [patch] awk(1): /usr/bin/awk fails mawk's FPE test
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 09 20:10:01 UTC 2008
>Closed-Date:    Fri Nov 25 22:27:39 UTC 2011
>Last-Modified:  Fri Nov 25 22:27:39 UTC 2011
>Originator:     Pedro F. Giffuni
>Release:        FreeBSD-6.3-Release
>Organization:
>Environment:
FreeBSD kakumen.cable.net.co 6.3-RELEASE FreeBSD 6.3-RELEASE #10: Sat Jan 19 01:13:55 COT 2008     root@kakumen.cable.net.co:/usr/src/sys/amd64/compile/SMP  amd64

>Description:
The historic behavior in 386BSD and FreeBSD 2.x was to trap all Floating Point Exceptions. 

Now we are supporting IEEE754 properly so we don't trap FPE's anymore but for some unknown reason printing the result of a division from zero in the one-true-awk returns an inconsistent code so we are failing mawk's fpe_test.

Restoring the historic behavior for awk (nawk used to pass this test in FreeBSD 2.x) gives a consistent result: it is also arguable that it's better to know when you are doing stupid things in your script instead of trying to find out the inconsistency later.
>How-To-Repeat:
Switching to nawk the fpe_test included in lang/mawk we get:

kakumen# ./fpe_test
testing division by zero
nawk BEGIN{ print 4/0 }
nawk: division by zero
source line number 1

testing overflow
nawk BEGIN {
  x = 100
  do { y = x ; x *= 1000 } while ( y != x )
  print "loop terminated"
}
loop terminated

testing domain error
nawk BEGIN{ print log(-8) }
nan


==============================
return1 = 2
return2 = 0
return3 = 0
results are not consistent
return values should all be 0 if ignoring FPEs (e.g. with IEEE754)
or all 2 if trapping FPEs
compilation defines for floating point are incorrect
>Fix:
--- main.c.orig	2007-05-01 16:05:28.000000000 -0500
+++ main.c	2008-07-08 15:33:37.000000000 -0500
@@ -34,6 +34,8 @@
 #include "awk.h"
 #include "ytab.h"
 
+#include <fenv.h>
+
 extern	char	**environ;
 extern	int	nfields;
 
@@ -67,6 +69,7 @@
 		exit(1);
 	}
 	signal(SIGFPE, fpecatch);
+	feenableexcept(FE_DIVBYZERO|FE_INEXACT|FE_OVERFLOW);
 	yyin = NULL;
 	symtab = makesymtab(NSYMTAB/NSYMTAB);
 	while (argc > 1 && argv[1][0] == '-' && argv[1][1] != '\0') {


>Release-Note:
>Audit-Trail:

From: "Pedro F. Giffuni" <giffunip@tutopia.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/125449: [patch] awk(1): /usr/bin/awk fails mawk's FPE test
Date: Sat, 26 Mar 2011 10:14:22 -0700 (PDT)

 Let's just close this.
 
 We are using the default nawk behaviour since we moved to it
 and no one seems to notice the difference.
 
 
       
State-Changed-From-To: open->closed 
State-Changed-By: bapt 
State-Changed-When: Fri Nov 25 22:27:38 UTC 2011 
State-Changed-Why:  
closed per submitter request 

http://www.freebsd.org/cgi/query-pr.cgi?pr=125449 
>Unformatted:
