Subject: lib/4466: e_atan2.c WARNS'ified incorrectly
To: None <gnats-bugs@gnats.netbsd.org>
From: Erik Bertelsen <erik@erik-be.uni-c.dk>
List: netbsd-bugs
Date: 11/11/1997 11:50:15
>Number:         4466
>Category:       lib
>Synopsis:       e_atan2.c WARNS'ified incorrectly
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 11 02:05:03 1997
>Last-Modified:
>Originator:     Erik Bertelsen
>Organization:
	
>Release:        NetBSD-1.3_ALPHA, 12. Nov 1997
>Environment:
	
System: NetBSD erik-be.uni-c.dk 1.3_ALPHA NetBSD 1.3_ALPHA (ERIKBE) #66: Thu Nov 6 12:03:15 MET 1997 erik@erik-be.uni-c.dk:/sw/NetBSD/src/sys/arch/i386/compile/ERIKBE i386


>Description:
While installing perl5, I've noticed that it failed one of its tests
(lib/complex).

After discussions on the -current mailing list it was clear that this
problem does exist for several (all?) ports of NetBSD, and that it
has been introduced since release 1.2.1.

The problem was then narrowed down to atan(), as illustrated by the following
program written by Giles Lean:

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

int
main()
{
	printf("%.15f\n", atan2(1, 1.2));
	exit(0);
}

Giles has demonstrated that the output from this program is

0.785398163397448 on 1.3_ALPHA with the broken library
0.694738276196703 on 1.1

I have verified that by removing the extra parenthesis added to
version 1.9 of e_atan.2, Giles' program produces the same output
as on previous releases, and that perl5 actually passes all tests.

The following patch is an attempt to re-insert this () in a better
place to WARNSify e_atan2.c. With this patch, Giles' program still
gives the original output. Please review it once more before 
committing it :-)  This patch also makes perl pass all tests on
i386.

The problem has been verified to exist on NetBSD/i386 and on /mac68k,
while a pmax fails differently -- I'll investigate this later.

regards
Erik Bertelsen

>How-To-Repeat:
>Fix:
Index: e_atan2.c
===================================================================
RCS file: /sw/cvs-base/src/lib/libm/src/e_atan2.c,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 e_atan2.c
*** e_atan2.c	1997/10/10 14:20:16	1.1.1.2
--- e_atan2.c	1997/11/11 10:35:37
***************
*** 75,81 ****
  	if(((ix|((lx|-lx)>>31))>0x7ff00000)||
  	   ((iy|((ly|-ly)>>31))>0x7ff00000))	/* x or y is NaN */
  	   return x+y;
! 	if((hx-(0x3ff00000|lx))==0) return atan(y);   /* x=1.0 */
  	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
  
      /* when y = 0 */
--- 75,81 ----
  	if(((ix|((lx|-lx)>>31))>0x7ff00000)||
  	   ((iy|((ly|-ly)>>31))>0x7ff00000))	/* x or y is NaN */
  	   return x+y;
! 	if(((hx-0x3ff00000)|lx)==0) return atan(y);   /* x=1.0 */
  	m = ((hy>>31)&1)|((hx>>30)&2);	/* 2*sign(x)+sign(y) */
  
      /* when y = 0 */
>Audit-Trail:
>Unformatted: