summaryrefslogtreecommitdiff
path: root/gcc/testsuite/c-c++-common/torture/complex-sign-mul-one.c
blob: ad02a2cd666e0e71ff225fa403193325ac8883c9 (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
/* Test complex arithmetic with signed zeros.  Pure complex
   multiplication with 1.0 + 0.0i.  */
/* { dg-do run } */
/* { dg-options "-std=gnu99" { target c } } */

#include "complex-sign.h"

#define CHECK_MUL_INT(TYPE, COPY, ZERO, ZEROI, ONE, S1, S2, SR, SI)	\
  do {									\
    _Complex TYPE a1, b1, c1;						\
    volatile _Complex TYPE a2, b2, c2;					\
    a1 = ENCODE(ZERO, ZEROI, S1, S2);					\
    CHECK_RES (a1, COPY, S1, S2);					\
    b1 = ONE + ZEROI;							\
    c1 = a1 * b1;							\
    CHECK_RES (c1, COPY, SR, SI);					\
    c1 = a1 * (ONE + ZEROI);						\
    CHECK_RES (c1, COPY, SR, SI);					\
    a2 = ENCODE(ZERO, ZEROI, S1, S2);					\
    CHECK_RES (a2, COPY, S1, S2);					\
    b2 = ONE + ZEROI;							\
    c2 = a2 * b2;							\
    CHECK_RES (c2, COPY, SR, SI);					\
    c2 = a2 * (ONE + ZEROI);						\
    CHECK_RES (c2, COPY, SR, SI);					\
  } while (0)

#define CHECK_MUL(TYPE, COPY, ZERO, ZEROI, ONE)			\
  do {								\
    CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, +, +, +, +);	\
    CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, +, -, +, +);	\
    CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, -, +, -, +);	\
    CHECK_MUL_INT (TYPE, COPY, ZERO, ZEROI, ONE, -, -, +, -);	\
  } while (0)

void
check_mul_float (void)
{
#ifndef __SPU__
  CHECK_MUL (float, __builtin_copysignf, 0.0f, 0.0if, 1.0f);
#endif
}

void
check_mul_double (void)
{
  CHECK_MUL (double, __builtin_copysign, 0.0, 0.0i, 1.0);
}

void
check_mul_long_double (void)
{
  CHECK_MUL (long double, __builtin_copysignl, 0.0l, 0.0il, 1.0l);
}

int
main (void)
{
  check_mul_float ();
  check_mul_double ();
  check_mul_long_double ();
  exit (0);
}