delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2007/05/03/15:02:24

X-Spam-Check-By: sourceware.org
Message-ID: <ba40711f0705031201q2ae9a3e9lf087fb55ab720be@mail.gmail.com>
Date: Thu, 3 May 2007 15:01:45 -0400
From: "Lev Bishop" <lev DOT bishop AT gmail DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: newlib?: pow function can produce incorrect results.
In-Reply-To: <476923.14782.qm@web59106.mail.re1.yahoo.com>
MIME-Version: 1.0
References: <476923 DOT 14782 DOT qm AT web59106 DOT mail DOT re1 DOT yahoo DOT com>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On 5/2/07, Cary R.  wrote:

> > Other potentially controversial special cases (may or may not be
> > handled correctly by newlib -- I didn't check) are:
> > atan2(+-0,-0)=+-pi
> > atan2(+-0,+0)=+-0
>
> newlib and my version of glibc return +0 for all these cases.

Hmm.... *my* version of glibc gets all 4 cases right:

lsb32 AT cmt:~> cat atan2.c
#include <stdio.h>
#include <math.h>
int main()
{
  double zero, mzero;
  zero = 0.0;
  mzero= -1.0*0;

  printf("Using +0=%f -0=%f\n",zero,mzero);
  printf("atan2(+0,+0)=%f\n",atan2(zero,zero));
  printf("atan2(-0,+0)=%f\n",atan2(mzero,zero));
  printf("atan2(+0,-0)=%f\n",atan2(zero,mzero));
  printf("atan2(-0,-0)=%f\n",atan2(mzero,mzero));
  return 0;
}
lsb32 AT cmt:~> gcc -Wall -fno-builtin atan2.c -lm &&./a.out
Using +0=0.000000 -0=-0.000000
atan2(+0,+0)=0.000000
atan2(-0,+0)=-0.000000
atan2(+0,-0)=3.141593
atan2(-0,-0)=-3.141593

lsb32 AT cmt:~> /lib/libc.so.6
GNU C Library development release version 2.4 (20060526), by Roland
McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Configured for i686-suse-linux.
Compiled by GNU CC version 4.1.0 (SUSE Linux).
Compiled on a Linux 2.6.16 system on 2006-05-26.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        GNU libio by Per Bothner
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        NoVersion patch for broken glibc 2.0 binaries
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

lsb32 AT cmt:~> uname -a
Linux cmt 2.6.16.21-0.25-smp #1 SMP Tue Sep 19 07:26:15 UTC 2006 i686
i686 i386 GNU/Linux

Newlib gets it wrong and puts out +0 in all cases, as you said, but
interestingly gcc -mno-cygwin gets all cases correct (although you
have to work a bit harder to prove that because mingw's printf()
doesn't distinguish +0 and -0 in it's output).

Lev

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019