From rhh@rr.com  Mon Sep  4 05:06:20 2000
Return-Path: <rhh@rr.com>
Received: from rr.com (rdu25-12-060.nc.rr.com [24.25.12.60])
	by hub.freebsd.org (Postfix) with ESMTP id 6AFE837B424
	for <FreeBSD-gnats-submit@freebsd.org>; Mon,  4 Sep 2000 05:06:19 -0700 (PDT)
Received: (from rhh@localhost)
	by rr.com (8.9.3/8.9.3) id IAA01191;
	Mon, 4 Sep 2000 08:09:15 -0400 (EDT)
	(envelope-from rhh)
Message-Id: <200009041209.IAA01191@rr.com>
Date: Mon, 4 Sep 2000 08:09:15 -0400 (EDT)
From: aa8vb@nc.rr.com
Sender: rhh@rr.com
Reply-To: aa8vb@nc.rr.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: pow() ERANGE bug
X-Send-Pr-Version: 3.2

>Number:         21024
>Category:       docs
>Synopsis:       pow() ERANGE bug
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bde
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          doc-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Sep 04 05:10:01 PDT 2000
>Closed-Date:    Sat Dec 31 23:39:19 GMT 2005
>Last-Modified:  Sat Dec 31 23:39:19 GMT 2005
>Originator:     Randall Hopper
>Release:        FreeBSD 3.4-RELEASE i386
>Organization:
self
>Environment:

	Stock 3.4-RELEASE.

>Description:

According to the man page:

   The functions exp(), expm1(), pow() detect if the computed value will
   overflow, set the global variable errno to ERANGE, and ...

However, pow() does not set errno to ERANGE on overflow.


>How-To-Repeat:

Example:  The attached code generates:  Inf  0

The output should be:  Inf 34    (34 is ERANGE)

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

main()
{
   fpsetmask(0);
   printf( "%g\n", pow(1e300,2) );
   pow(1e300,2);
   printf( "%d\n", errno );
}


>Fix:
	
	Please update the pow() function to set errno on overflow.  Might
also check other likely suspects such as exp() and expm1().  --Thanks.


>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: aa8vb@nc.rr.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: bin/21024: pow() ERANGE bug
Date: Tue, 5 Sep 2000 17:40:55 +1100 (EST)

 On Mon, 4 Sep 2000 aa8vb@nc.rr.com wrote:
 
 > >Description:
 > 
 > According to the man page:
 > 
 >    The functions exp(), expm1(), pow() detect if the computed value will
 >    overflow, set the global variable errno to ERANGE, and ...
 
 This is mainly a bug in the man page.  This part of it describes the
 behaviour of pow() in the old BSD libm, but we use Sun's fdlibm.  The
 man page had already rotted for exp() and expm1() in the old libm --
 errno was set for pow() on Vaxes and Tahoes, but was not set for exp()
 or expm1() on any machine.
 
 The man page actually says:
 
     ... set the global variable errno to ERANGE [no comma here] and cause
     a reserved operand fault on a Vax or Tahoe.
 
 so it is not clear that ERANGE is set except on Vaxes and Tahoes.  In fact,
 according to the sources it _is_ only set on Vaxes and Tahoes (all settings
 of errno in the old libm are done by infnan.s which only exists for Vaxes
 and Tahoes).
 
 > However, pow() does not set errno to ERANGE on overflow.
 
 The actual behaviour on overflow is:
 
     (1) Attempt to set the IEEE exception flags (if any) in an IEEE'ish
 	way by evaluating the overflowing expression `huge*huge' where
 	`huge' is `static const double huge = 1.0e300'.  This normally
 	fails due to dubious compiler optimizations (gcc evaluates the
 	expression at compile time and doesn't generate code to set the
 	flags at runtime).
     (2) If libm is compiled with -D_POSIX_MODE and the library mode is not
 	changed from the resulting default, then set errno to ERANGE.
 	-D_POSIX_MODE is not the default and not recommended, although it
 	is required for "POSIX" (actually old Standard C) conformance --
 	see src/lib/msun/Makefile.  It mainly slows things down and messes
 	up the return value for domain errors.  There are other configuration
 	flags/library modes which mess up the return value even for range
 	errors.
 
 This non-conformance with old Standard C is unlikely to be changed, since
 setting errno for math functions is considered harmful and is not required 
 in the current C standard.
 
 This PR should be turned into one about the libm man pages.  The descriptions
 of error handling are anachronistic and/or incomplete.  As an example of
 incompleteness, there are 19 special cases for pow() (see the sources) and
 only a couple of these are described in the man page.
 
 Bruce
 
 
Class-Changed-From-To: sw-bug->doc-bug 
Class-Changed-By: mi 
Class-Changed-When: Tue Aug 20 09:26:57 PDT 2002 
Class-Changed-Why:  
After getting bitten by the pow(3) inaccuracies, I was about to 
file a PR correcting it, but found this one alredy filed (two years 
old). Per Bruce's suggestion reclassify it as a documentation problem 
and assign to Bruce :-) 


Responsible-Changed-From-To: freebsd-bugs->bde 
Responsible-Changed-By: mi 
Responsible-Changed-When: Tue Aug 20 09:26:57 PDT 2002 
Responsible-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=21024 

From: "Siebrand Mazeland" <s.mazeland@xs4all.nl>
To: <bug-followup@FreeBSD.org>, <aa8vb@nc.rr.com>
Cc:  
Subject: Re: docs/21024: pow() ERANGE bug
Date: Sat, 31 Dec 2005 17:23:14 +0100

 The man page discussed in this PR has had many changes since this PR was
 filed back in 2000. It appears no longer relevant to src/lib/msun/man/exp.3.
 I suggest to close this PR.
 
 http://www.freebsd.org/cgi/query-pr.cgi?pr=docs/21024
 
State-Changed-From-To: open->closed 
State-Changed-By: bde 
State-Changed-When: Sat Dec 31 23:33:59 UTC 2005 
State-Changed-Why:  
As indicated in recent followup, the man page no longer misclaims that 
pow() sets errno to ERANGE on overflow.  (Such setting is a C90 
misfeature that has never been supported.) 

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