summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/ieee/copysign2.c
blob: fac7ab3a530c6527ddc8c532d2e8086e36051554 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <string.h>
#include <stdlib.h>
#include <float.h>

#define fpsizeoff	sizeof(float)
#define fpsizeof	sizeof(double)
#define fpsizeofl	sizeof(long double)

/* Work around the fact that with the Intel double-extended precision,
   we've got a 10 byte type stuffed into some amount of padding.  And
   the fact that -ffloat-store is going to stuff this value temporarily
   into some bit of stack frame that we've no control over and can't zero.  */
#if LDBL_MANT_DIG == 64
# if defined(__i386__) || defined(__x86_64__) || defined (__ia64__)
#  undef fpsizeofl
#  define fpsizeofl	10
# endif
#endif

/* Work around the fact that the sign of the second double in the IBM
   double-double format is not strictly specified when it contains a zero.
   For instance, -0.0L can be represented with either (-0.0, +0.0) or
   (-0.0, -0.0).  The former is what we'll get from the compiler when it
   builds constants; the later is what we'll get from the negation operator
   at runtime.  */
/* ??? This hack only works for big-endian, which is fortunately true for
   all of AIX, Darwin, and Irix.  */
#if LDBL_MANT_DIG == 106
# undef fpsizeofl
# define fpsizeofl	sizeof(double)
#endif


#define TEST(TYPE, EXT)						\
static TYPE Y##EXT[] = {					\
  2.0, -2.0, -2.0, -2.0, -2.0, 2.0, -0.0, __builtin_inf##EXT ()	\
};								\
static const TYPE Z##EXT[] = {					\
  1.0, -1.0, -1.0, -0.0, -0.0, 0.0, -__builtin_inf##EXT (),	\
  __builtin_nan##EXT ("")					\
};								\
								\
void test##EXT (void)						\
{								\
  TYPE r[8];							\
  int i;							\
  r[0] = __builtin_copysign##EXT (1.0, Y##EXT[0]);		\
  r[1] = __builtin_copysign##EXT (1.0, Y##EXT[1]);		\
  r[2] = __builtin_copysign##EXT (-1.0, Y##EXT[2]);		\
  r[3] = __builtin_copysign##EXT (0.0, Y##EXT[3]);		\
  r[4] = __builtin_copysign##EXT (-0.0, Y##EXT[4]);		\
  r[5] = __builtin_copysign##EXT (-0.0, Y##EXT[5]);		\
  r[6] = __builtin_copysign##EXT (__builtin_inf##EXT (), Y##EXT[6]); \
  r[7] = __builtin_copysign##EXT (-__builtin_nan##EXT (""), Y##EXT[7]); \
  for (i = 0; i < 8; ++i)					\
    if (memcmp (r+i, Z##EXT+i, fpsizeof##EXT) != 0)		\
      abort ();							\
}

TEST(float, f)
TEST(double, )
TEST(long double, l)

int main()
{
  testf();
  test();
  testl();
  return 0;
}