<< Back to previous view

[PCC-382] sign issue with tanh/tanhf(-0.0) result Created: 23/Sep/11  Updated: 23/Mar/12

Status: Resolved
Project: pcc
Component/s: amd64 target
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Nicolas Joly Assignee: Anders Magnusson
Resolution: Fixed Votes: 0
Environment: NetBSD lynche.sis.pasteur.fr 5.99.55 NetBSD 5.99.55 (LYNCHE) #2: Mon Sep 12 10:56:41 CEST 2011 njoly@lynche.sis.pasteur.fr:/local/src/NetBSD/obj.amd64/sys/arch/amd64/compile/LYNCHE amd64
pcc 1.1.0.DEVEL 20110922 for x86_64-unknown-netbsd5.99.55


 Description   
The following sample code do fail with pcc on amd64, but succeed with gcc (works fine for i386 with both pcc and gcc).

njoly@lynche [tmp/pcc]> cat sample.c

#include <assert.h>
#include <err.h>
#include <math.h>

int main() {
  double d;
  float f;

  f = tanhf(-0.0);
  warnx("%e %d", f, signbit(f));
  assert(signbit(f) != 0);

  d = tanh(-0.0);
  warnx("%e %d", d, signbit(d));
  assert(signbit(d) != 0);

  return 0; }

njoly@lynche [tmp/pcc]> pcc -g -Wall -Werror -o sample sample.c -lm
njoly@lynche [tmp/pcc]> ./sample
sample: 0.000000e+00 0
assertion "signbit(f) != 0" failed: file "sample.c", line 12, function "main"
zsh: abort (core dumped) ./sample

njoly@lynche [tmp/pcc]> gcc -g -Wall -Werror -o sample sample.c -lm
njoly@lynche [tmp/pcc]> ./sample
sample: -0.000000e+00 1
sample: -0.000000e+00 1


 Comments   
Comment by Nicolas Joly [ 09/Oct/11 01:25 PM ]
Looking into this one a little further show that the problem is not related with atan(3) at all ...
assigning a negative zero to a float/double variable triggers the very same problem:

njoly@lynche [tmp/pcc]> cat sample.c

#include <assert.h>
#include <math.h>

int main() {
  double d;
  float f;

  f = -0.0;
  assert(signbit(f) != 0);

  d = -0.0;
  assert(signbit(d) != 0);

  return 0; }
njoly@lynche [tmp/pcc]> pcc -g -Wall -Werror -o sample sample.c
njoly@lynche [tmp/pcc]> ./sample
assertion "signbit(f) != 0" failed: file "sample.c", line 10, function "main"
zsh: abort (core dumped) ./sample
Comment by Anders Magnusson [ 23/Mar/12 06:04 PM ]
Do not loose negative zero when comparing zeroes.
Generated at Sat Apr 19 03:47:35 CEST 2014 using JIRA Enterprise Edition, Version: 3.13.1-#333.