Skip to content

Commit

Permalink
* gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148511 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
ghazi committed Jun 16, 2009
1 parent 377d721 commit ea1addb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 31 deletions.
4 changes: 4 additions & 0 deletions gcc/testsuite/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2009-06-16 Kaveh R. Ghazi <[email protected]>

* gcc.dg/torture/builtin-math-6.c: Robustify and fix clog cases.

2009-06-15 Jakub Jelinek <[email protected]>

* gcc.dg/builtin-object-size-7.c: New test.
Expand Down
78 changes: 47 additions & 31 deletions gcc/testsuite/gcc.dg/torture/builtin-math-6.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,73 @@
/* All references to link_error should go away at compile-time. */
extern void link_error(int);

/* Return TRUE if the sign of X != sign of Y. This is important when
comparing signed zeros. */
/* Return TRUE if the signs of floating point values X and Y are not
equal. This is important when comparing signed zeros. */
#define CKSGN_F(X,Y) \
(__builtin_copysignf(1.0F,(X)) != __builtin_copysignf(1.0F,(Y)))
(__builtin_copysignf(1,(X)) != __builtin_copysignf(1,(Y)))
#define CKSGN(X,Y) \
(__builtin_copysign(1.0,(X)) != __builtin_copysign(1.0,(Y)))
(__builtin_copysign(1,(X)) != __builtin_copysign(1,(Y)))
#define CKSGN_L(X,Y) \
(__builtin_copysignl(1.0L,(X)) != __builtin_copysignl(1.0L,(Y)))
(__builtin_copysignl(1,(X)) != __builtin_copysignl(1,(Y)))

/* Return TRUE if signs of the real parts, and the signs of the
imaginary parts, of X and Y are not equal. */
#define COMPLEX_CKSGN_F(X,Y) \
(CKSGN_F(__real__ (X), __real__ (Y)) || CKSGN_F (__imag__ (X), __imag__ (Y)))
#define COMPLEX_CKSGN(X,Y) \
(CKSGN(__real__ (X), __real__ (Y)) || CKSGN (__imag__ (X), __imag__ (Y)))
#define COMPLEX_CKSGN_L(X,Y) \
(CKSGN_L(__real__ (X), __real__ (Y)) || CKSGN_L (__imag__ (X), __imag__ (Y)))

/* For complex numbers, test that FUNC(ARG) == (RES). */
#define TESTIT_COMPLEX(FUNC, ARG, RES) do { \
if (__builtin_##FUNC##f(ARG) != (RES) \
|| CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \
|| CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \
|| COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
link_error(__LINE__); \
if (__builtin_##FUNC(ARG) != (RES) \
|| CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \
|| CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__); \
if (__builtin_##FUNC##l(ARG) != (RES) \
|| CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \
|| CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \
|| COMPLEX_CKSGN_L(__builtin_##FUNC##l(ARG), (RES))) \
link_error(__LINE__); \
} while (0)

/* Return TRUE if X differs from EXPECTED by more than 1%. If
EXPECTED is zero, then any difference may return TRUE. We don't
worry about signed zeros. */
#define DIFF1PCT_F(X,EXPECTED) \
(__builtin_fabsf((X)-(EXPECTED)) * 100 > __builtin_fabsf(EXPECTED))
#define DIFF1PCT(X,EXPECTED) \
(__builtin_fabs((X)-(EXPECTED)) * 100 > __builtin_fabs(EXPECTED))
#define DIFF1PCT_L(X,EXPECTED) \
(__builtin_fabsl((X)-(EXPECTED)) * 100 > __builtin_fabsl(EXPECTED))

/* Return TRUE if complex value X differs from EXPECTED by more than
1% in either the real or imaginary parts. */
#define COMPLEX_DIFF1PCT_F(X,EXPECTED) \
(DIFF1PCT_F(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT_F(__imag__ (X), __imag__ (EXPECTED)))
#define COMPLEX_DIFF1PCT(X,EXPECTED) \
(DIFF1PCT(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT(__imag__ (X), __imag__ (EXPECTED)))
#define COMPLEX_DIFF1PCT_L(X,EXPECTED) \
(DIFF1PCT_L(__real__ (X), __real__ (EXPECTED)) \
|| DIFF1PCT_L(__imag__ (X), __imag__ (EXPECTED)))

/* Range test, for complex numbers check that FUNC(ARG) is within 1%
of RES. This is NOT a test for accuracy to the last-bit, we're
merely checking that we get relatively sane results. I.e. the GCC
builtin is hooked up to the correct MPC function call. We first
check the magnitude and then the sign. */
#define TESTIT_COMPLEX_R(FUNC, ARG, RES) do { \
if (__builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__real__ (RES)) * 0.99F \
|| __builtin_fabsf(__real__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__real__ (RES)) * 1.01F \
|| __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) < __builtin_fabsf(__imag__ (RES)) * 0.99F \
|| __builtin_fabsf(__imag__ __builtin_##FUNC##f(ARG)) > __builtin_fabsf(__imag__ (RES)) * 1.01F \
|| CKSGN_F(__real__ __builtin_##FUNC##f(ARG), __real__ (RES)) \
|| CKSGN_F(__imag__ __builtin_##FUNC##f(ARG), __imag__ (RES))) \
if (COMPLEX_DIFF1PCT_F (__builtin_##FUNC##f(ARG), (RES)) \
|| COMPLEX_CKSGN_F(__builtin_##FUNC##f(ARG), (RES))) \
link_error(__LINE__); \
if (__builtin_fabs(__real__ __builtin_##FUNC(ARG)) < __builtin_fabs(__real__ (RES)) * 0.99F \
|| __builtin_fabs(__real__ __builtin_##FUNC(ARG)) > __builtin_fabs(__real__ (RES)) * 1.01F \
|| __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) < __builtin_fabs(__imag__ (RES)) * 0.99F \
|| __builtin_fabs(__imag__ __builtin_##FUNC(ARG)) > __builtin_fabs(__imag__ (RES)) * 1.01F \
|| CKSGN(__real__ __builtin_##FUNC(ARG), __real__ (RES)) \
|| CKSGN(__imag__ __builtin_##FUNC(ARG), __imag__ (RES))) \
if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__); \
if (__builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__real__ (RES)) * 0.99F \
|| __builtin_fabsl(__real__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__real__ (RES)) * 1.01F \
|| __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) < __builtin_fabsl(__imag__ (RES)) * 0.99F \
|| __builtin_fabsl(__imag__ __builtin_##FUNC##l(ARG)) > __builtin_fabsl(__imag__ (RES)) * 1.01F \
|| CKSGN_L(__real__ __builtin_##FUNC##l(ARG), __real__ (RES)) \
|| CKSGN_L(__imag__ __builtin_##FUNC##l(ARG), __imag__ (RES))) \
if (COMPLEX_DIFF1PCT (__builtin_##FUNC(ARG), (RES)) \
|| COMPLEX_CKSGN(__builtin_##FUNC(ARG), (RES))) \
link_error(__LINE__); \
} while (0)

Expand Down Expand Up @@ -129,8 +145,8 @@ int main (void)

TESTIT_COMPLEX (clog, 1.0F, 0.0F);
TESTIT_COMPLEX_R (clog, -1.0F, 3.141593FI);
TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), 0.0F);
TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), 3.141593FI);
TESTIT_COMPLEX (clog, __builtin_conjf(1.0F), __builtin_conjf(0.0F)); /* Fails with mpc-0.6. */
TESTIT_COMPLEX_R (clog, __builtin_conjf(-1.0F), __builtin_conjf(3.141593FI)); /* Fails with mpc-0.6. */

TESTIT_COMPLEX_R (clog, 3.45678F + 2.34567FI, 1.429713F + 0.596199FI);
TESTIT_COMPLEX_R (clog, 3.45678F - 2.34567FI, 1.429713F - 0.596199FI);
Expand Down

0 comments on commit ea1addb

Please sign in to comment.