]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/torture/builtin-frexp-1.c
1 /* Copyright (C) 2007 Free Software Foundation.
3 Verify that built-in folding of frexp is correctly performed by the
6 Origin: Kaveh R. Ghazi, February 21, 2007. */
9 /* { dg-options "-fno-finite-math-only" { target sh*-*-* } } */
11 extern void link_error(int);
13 /* Return TRUE if the sign of X != sign of Y. This is important when
14 comparing signed zeros. */
15 #define CKSGN_F(X,Y) \
16 (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
18 (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
19 #define CKSGN_L(X,Y) \
20 (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
22 /* We can only check the exponent when optimizing since we rely on
23 other optimizations to propagate the value. TRUE means an error
26 #define CKEXP(X,Y) X != Y
31 /* Test that frexp(ARG,&i) == RES && i == EXP. Check the sign in
33 #define TESTIT_FREXP(ARG,RES,EXP) do { \
35 if (__builtin_frexpf(ARG##f,&i) != RES##f \
37 || CKSGN_F(__builtin_frexpf(ARG##f,&i),RES##f)) \
38 link_error(__LINE__); \
40 if (__builtin_frexp(ARG,&i) != RES \
42 || CKSGN(__builtin_frexp(ARG,&i),RES)) \
43 link_error(__LINE__); \
45 if (__builtin_frexpl(ARG##l,&i) != RES##l \
47 || CKSGN_L(__builtin_frexpl(ARG##l,&i),RES##l)) \
48 link_error(__LINE__); \
51 /* Test that FUNCRES(frexp(NEG FUNCARG(ARGARG),&i)) is false. Check
52 the sign as well. Ensure side-effects are evaluated in i. */
53 #define TESTIT_FREXP2(NEG,FUNCARG,ARGARG,FUNCRES) do { \
55 if (!__builtin_##FUNCRES##f(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),&i)) \
56 || CKSGN_F(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##f(ARGARG)) \
58 link_error(__LINE__); \
59 if (!__builtin_##FUNCRES(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),&i)) \
60 || CKSGN(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG(ARGARG)) \
62 link_error(__LINE__); \
63 if (!__builtin_##FUNCRES##l(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),&i)) \
64 || CKSGN_L(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##l(ARGARG)) \
66 link_error(__LINE__); \
69 void __attribute__ ((__noinline__
))
72 /* Test that frexp(ARG1,&i) -> ARG2 && i == ARG3. */
73 TESTIT_FREXP (-0x1p
40, -0.5, 41);
74 TESTIT_FREXP (-0x1p
30, -0.5, 31);
75 TESTIT_FREXP (-0x1p
20, -0.5, 21);
76 TESTIT_FREXP (-0x1p
10, -0.5, 11);
77 TESTIT_FREXP (-0x1p
5, -0.5, 6);
78 TESTIT_FREXP (-100/3.0, -100/192.0, 6);
79 TESTIT_FREXP (-1.5, -0.75, 1);
80 TESTIT_FREXP (-1.0, -0.5, 1);
81 TESTIT_FREXP (-1/3.0, -2/3.0, -1);
82 TESTIT_FREXP (-1/9.0, -8/9.0, -3);
83 TESTIT_FREXP (-0x1p
-5, -0.5, -4);
84 TESTIT_FREXP (-0x1p
-10, -0.5, -9);
85 TESTIT_FREXP (-0x1p
-20, -0.5, -19);
86 TESTIT_FREXP (-0x1p
-30, -0.5, -29);
87 TESTIT_FREXP (-0x1p
-40, -0.5, -39);
88 TESTIT_FREXP (-0.0, -0.0, 0);
89 TESTIT_FREXP (0.0, 0.0, 0);
90 TESTIT_FREXP (0x1p
-40, 0.5, -39);
91 TESTIT_FREXP (0x1p
-30, 0.5, -29);
92 TESTIT_FREXP (0x1p
-20, 0.5, -19);
93 TESTIT_FREXP (0x1p
-10, 0.5, -9);
94 TESTIT_FREXP (0x1p
-5, 0.5, -4);
95 TESTIT_FREXP (1/9.0, 8/9.0, -3);
96 TESTIT_FREXP (1/3.0, 2/3.0, -1);
97 TESTIT_FREXP (1.0, 0.5, 1);
98 TESTIT_FREXP (1.5, 0.75, 1);
99 TESTIT_FREXP (100/3.0, 100/192.0, 6);
100 TESTIT_FREXP (0x1p
5, 0.5, 6);
101 TESTIT_FREXP (0x1p
10, 0.5, 11);
102 TESTIT_FREXP (0x1p
20, 0.5, 21);
103 TESTIT_FREXP (0x1p
30, 0.5, 31);
104 TESTIT_FREXP (0x1p
40, 0.5, 41);
106 /* Test for frexp(+-Inf,&i) -> +-Inf and frexp(+-NaN,&i) -> +-NaN.
107 Exponent is left unspecified, but we test for side-effects. */
108 TESTIT_FREXP2 ( ,inf
, , isinf
);
109 TESTIT_FREXP2 (- ,inf
, , isinf
);
110 TESTIT_FREXP2 ( ,nan
, "", isnan
);
111 TESTIT_FREXP2 (- ,nan
, "", isnan
);