[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
HPPA and -0.0L
From: |
Bruno Haible |
Subject: |
HPPA and -0.0L |
Date: |
Sun, 13 Apr 2008 21:20:54 +0200 |
User-agent: |
KMail/1.5.4 |
On most platforms, negating a positive zero yields a negative zero.
Not so on HP-UX/HPPA: This platform has distinct positive and negative zeroes,
but negating a positive zero yields a positive zero (in 'long double' format).
Test program:
=======================================================
#include <math.h>
#include <stdio.h>
#include <string.h>
long double x = 1.0L;
long double y = -0.0L;
long double z = 0.0L;
int different_from_plus_zero (long double arg)
{
return memcmp (&arg, &z, sizeof (z)) != 0;
}
int main()
{
printf ("%Lf\n", x / y);
printf ("%d\n", x / y < 0);
printf ("%d\n", signbit (x/y) != 0);
printf ("%d\n", different_from_plus_zero (y));
#define x 1.0L
#define y -0.0L
printf ("%Lf\n", x / y);
printf ("%d\n", x / y < 0);
printf ("%d\n", signbit (x/y) != 0);
printf ("%d\n", different_from_plus_zero (y));
#undef y
#define y -z
printf ("%Lf\n", x / y);
printf ("%d\n", x / y < 0);
printf ("%d\n", signbit (x/y) != 0);
printf ("%d\n", different_from_plus_zero (y));
return 0;
}
=====================================================
When run on this platform, the result is:
-inf
1
1
1
-inf
1
1
1
inf
0
0
0
This causes a test failure in test-signbit.c. Fixing it like this:
2008-04-13 Bruno Haible <address@hidden>
Make test-signbit pass on HP-UX/hppa.
* tests/test-signbit.c (minus_zerol): New variable.
(test_signbitl): Use it.
*** tests/test-signbit.c.orig 2008-04-13 21:15:19.000000000 +0200
--- tests/test-signbit.c 2008-04-13 21:14:54.000000000 +0200
***************
*** 39,44 ****
--- 39,47 ----
float zerof = 0.0f;
double zerod = 0.0;
long double zerol = 0.0L;
+ /* We cannot use the expression '-zerol' here, because on HP-UX/hppa it
+ evaluates to 0.0L, not -0.0L. */
+ long double minus_zerol = -0.0L;
static void
test_signbitf ()
***************
*** 140,146 ****
ASSERT (signbit (-2.718e-30L));
/* Zeros. */
ASSERT (!signbit (0.0L));
! if (1.0L / -zerol < 0)
ASSERT (signbit (-0.0L));
else
ASSERT (!signbit (-0.0L));
--- 143,149 ----
ASSERT (signbit (-2.718e-30L));
/* Zeros. */
ASSERT (!signbit (0.0L));
! if (1.0L / minus_zerol < 0)
ASSERT (signbit (-0.0L));
else
ASSERT (!signbit (-0.0L));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- HPPA and -0.0L,
Bruno Haible <=