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. */
10 extern void link_error(int);
12 /* Return TRUE if the sign of X != sign of Y. This is important when
13 comparing signed zeros. */
14 #define CKSGN_F(X,Y) \
15 (__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
17 (__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
18 #define CKSGN_L(X,Y) \
19 (__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
21 /* We can only check the exponent when optimizing since we rely on
22 other optimizations to propagate the value. TRUE means an error
25 #define CKEXP(X,Y) X != Y
30 /* Test that frexp(ARG,&i) == RES && i == EXP. Check the sign in
32 #define TESTIT_FREXP(ARG,RES,EXP) do { \
34 if (__builtin_frexpf(ARG##f,&i) != RES##f \
36 || CKSGN_F(__builtin_frexpf(ARG##f,&i),RES##f)) \
37 link_error(__LINE__); \
39 if (__builtin_frexp(ARG,&i) != RES \
41 || CKSGN(__builtin_frexp(ARG,&i),RES)) \
42 link_error(__LINE__); \
44 if (__builtin_frexpl(ARG##l,&i) != RES##l \
46 || CKSGN_L(__builtin_frexpl(ARG##l,&i),RES##l)) \
47 link_error(__LINE__); \
50 /* Test that FUNCRES(frexp(NEG FUNCARG(ARGARG),&i)) is false. Check
51 the sign as well. Ensure side-effects are evaluated in i. */
52 #define TESTIT_FREXP2(NEG,FUNCARG,ARGARG,FUNCRES) do { \
54 if (!__builtin_##FUNCRES##f(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),&i)) \
55 || CKSGN_F(__builtin_frexpf(NEG __builtin_##FUNCARG##f(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##f(ARGARG)) \
57 link_error(__LINE__); \
58 if (!__builtin_##FUNCRES(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),&i)) \
59 || CKSGN(__builtin_frexp(NEG __builtin_##FUNCARG(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG(ARGARG)) \
61 link_error(__LINE__); \
62 if (!__builtin_##FUNCRES##l(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),&i)) \
63 || CKSGN_L(__builtin_frexpl(NEG __builtin_##FUNCARG##l(ARGARG),(i++,&i)), NEG __builtin_##FUNCARG##l(ARGARG)) \
65 link_error(__LINE__); \
68 void __attribute__ ((__noinline__
))
71 /* Test that frexp(ARG1,&i) -> ARG2 && i == ARG3. */
72 TESTIT_FREXP (-0x1p
40, -0.5, 41);
73 TESTIT_FREXP (-0x1p
30, -0.5, 31);
74 TESTIT_FREXP (-0x1p
20, -0.5, 21);
75 TESTIT_FREXP (-0x1p
10, -0.5, 11);
76 TESTIT_FREXP (-0x1p
5, -0.5, 6);
77 TESTIT_FREXP (-100/3.0, -100/192.0, 6);
78 TESTIT_FREXP (-1.5, -0.75, 1);
79 TESTIT_FREXP (-1.0, -0.5, 1);
80 TESTIT_FREXP (-1/3.0, -2/3.0, -1);
81 TESTIT_FREXP (-1/9.0, -8/9.0, -3);
82 TESTIT_FREXP (-0x1p
-5, -0.5, -4);
83 TESTIT_FREXP (-0x1p
-10, -0.5, -9);
84 TESTIT_FREXP (-0x1p
-20, -0.5, -19);
85 TESTIT_FREXP (-0x1p
-30, -0.5, -29);
86 TESTIT_FREXP (-0x1p
-40, -0.5, -39);
87 TESTIT_FREXP (-0.0, -0.0, 0);
88 TESTIT_FREXP (0.0, 0.0, 0);
89 TESTIT_FREXP (0x1p
-40, 0.5, -39);
90 TESTIT_FREXP (0x1p
-30, 0.5, -29);
91 TESTIT_FREXP (0x1p
-20, 0.5, -19);
92 TESTIT_FREXP (0x1p
-10, 0.5, -9);
93 TESTIT_FREXP (0x1p
-5, 0.5, -4);
94 TESTIT_FREXP (1/9.0, 8/9.0, -3);
95 TESTIT_FREXP (1/3.0, 2/3.0, -1);
96 TESTIT_FREXP (1.0, 0.5, 1);
97 TESTIT_FREXP (1.5, 0.75, 1);
98 TESTIT_FREXP (100/3.0, 100/192.0, 6);
99 TESTIT_FREXP (0x1p
5, 0.5, 6);
100 TESTIT_FREXP (0x1p
10, 0.5, 11);
101 TESTIT_FREXP (0x1p
20, 0.5, 21);
102 TESTIT_FREXP (0x1p
30, 0.5, 31);
103 TESTIT_FREXP (0x1p
40, 0.5, 41);
105 /* Test for frexp(+-Inf,&i) -> +-Inf and frexp(+-NaN,&i) -> +-NaN.
106 Exponent is left unspecified, but we test for side-effects. */
107 TESTIT_FREXP2 ( ,inf
, , isinf
);
108 TESTIT_FREXP2 (- ,inf
, , isinf
);
109 TESTIT_FREXP2 ( ,nan
, "", isnan
);
110 TESTIT_FREXP2 (- ,nan
, "", isnan
);