2018-04-09 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / fnegate-1.c
blobad0f4e09f134f012ac880cdacd8e8377a07794bb
1 /* Copyright (C) 2002 Free Software Foundation.
3 Test floating point negation produces the expected results.
5 Written by Roger Sayle, 21st May 2002. */
7 /* { dg-do run } */
8 /* { dg-options "-O2 -ffast-math" } */
10 extern void abort ();
13 double
14 dneg (double x)
16 return -x;
19 double
20 dmult (double x)
22 return -1.0 * x;
25 double
26 ddiv (double x)
28 return x / -1.0;
32 float
33 fneg (float x)
35 return -x;
38 float
39 fmult (float x)
41 return -1.0f * x;
44 float
45 fdiv (float x)
47 return x / -1.0f;
51 void
52 ftest(float src, float dst)
54 if (fneg (src) != dst)
55 abort ();
57 if (src != fneg (dst))
58 abort ();
60 if (fmult (src) != dst)
61 abort ();
63 if (src != fmult (dst))
64 abort ();
66 if (fdiv (src) != dst)
67 abort ();
69 if (src != fdiv(dst))
70 abort ();
73 void
74 dtest(double src, double dst)
76 if (dneg (src) != dst)
77 abort ();
79 if (src != dneg (dst))
80 abort ();
82 if (dmult (src) != dst)
83 abort ();
85 if (src != dmult (dst))
86 abort ();
88 if (ddiv (src) != dst)
89 abort ();
91 if (src != ddiv(dst))
92 abort ();
96 int
97 main ()
99 ftest (1.0f, -1.0f);
100 ftest (2.0f, -2.0f);
101 ftest (-3.0f, 3.0f);
102 ftest (0.0f, -0.0f);
103 ftest (-0.0f, 0.0f);
105 dtest (1.0, -1.0);
106 dtest (2.0, -2.0);
107 dtest (-3.0, 3.0);
108 dtest (0.0, -0.0);
109 dtest (-0.0, 0.0);
111 return 0;