Debian Codegraph @

gcc/testsuite/g++.target/i386/excess-precision-11.C

raw
1 // Excess precision tests. Test excess precision is removed when
2 // necessary.
3 // { dg-do run }
4 // { dg-options "-O2 -mfpmath=387 -fexcess-precision=standard" }
5
6 #include <float.h>
7 #include <stdarg.h>
8
9 extern "C" void abort ();
10
11 volatile float f1 = 1.0f;
12 volatile float f2 = 0x1.0p-30f;
13 volatile float f3 = 0x1.0p-60f;
14 volatile double d1 = 1.0;
15 volatile double d2 = 0x1.0p-30;
16 volatile double d3 = 0x1.0p-60;
17 volatile double d3d = 0x1.0p-52;
18 volatile float fadd1 = 1.0f + 0x1.0p-30f;
19 volatile double dadd2 = 1.0 + 0x1.0p-30 + 0x1.0p-60;
20 volatile double dh = 0x1.0p-24;
21 volatile float fha = 1.0f + 0x1.0p-23f;
22
23 static inline void
24 check_float (float f)
25 {
26 if (f != fadd1)
27 abort ();
28 }
29
30 static inline void
31 check_float (double)
32 {
33 abort ();
34 }
35
36 static inline void
37 check_float (long double)
38 {
39 abort ();
40 }
41
42 static inline void
43 check_double (double d)
44 {
45 if (d != dadd2)
46 abort ();
47 }
48
49 static inline void
50 check_double (long double)
51 {
52 abort ();
53 }
54
55 static inline void
56 check_float2 (float f)
57 {
58 if (f != fha)
59 abort ();
60 }
61
62 struct S {
63 S () {}
64 S (float f) { if (f != fadd1) abort (); }
65 };
66
67 struct T {
68 T () {}
69 T (double d) { if (d != dadd2) abort (); }
70 };
71
72 static inline void
73 check_float3 (S)
74 {
75 }
76
77 static inline void
78 check_double2 (T)
79 {
80 }
81
82 void
83 test_call ()
84 {
85 check_float (f1 + f2);
86 check_double (f1 + f2);
87 check_double (d1 + d2 + d3);
88 /* Verify rounding direct to float without double rounding. */
89 if (sizeof (long double) > sizeof (double))
90 check_float2 (d1 + dh + d3);
91 else
92 check_float2 (d1 + dh + d3d);
93 check_float3 (f1 + f2);
94 check_double2 (f1 + f2);
95 check_double2 (d1 + d2 + d3);
96 S s1 = static_cast<S> (f1 + f2);
97 T t2 = static_cast<T> (f1 + f2);
98 T t3 = static_cast<T> (d1 + d2 + d3);
99 }
100
101 int
102 main ()
103 {
104 test_call ();
105 }