Back to index

glibc  2.9
test-tgmath-ret.c
Go to the documentation of this file.
00001 /* Test compilation of tgmath macros.
00002    Copyright (C) 2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Andreas Jaeger <aj@suse.de>, 2003.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <math.h>
00022 #include <complex.h>
00023 #include <tgmath.h>
00024 #include <stdio.h>
00025 
00026 static float fx;
00027 static double dx;
00028 static long double lx;
00029 static int errors = 0;
00030 
00031 static void
00032 our_error (const char *c)
00033 {
00034   puts (c);
00035   ++errors;
00036 }
00037 
00038 /* First function where the return type is constant.  */
00039 
00040 #define CHECK_RET_CONST_TYPE(func, rettype, arg, name) \
00041   if (sizeof (func (arg)) != sizeof (rettype))                              \
00042     our_error ("Return size of " #func " is wrong with " #name " argument");
00043 
00044 #define CHECK_RET_CONST_FLOAT(func, rettype) \
00045   CHECK_RET_CONST_TYPE (func, rettype, fx, float)
00046 #define CHECK_RET_CONST_DOUBLE(func, rettype) \
00047   CHECK_RET_CONST_TYPE (func, rettype, dx, double)
00048 #ifdef NO_LONG_DOUBLE
00049 # define CHECK_RET_CONST_LDOUBLE(func, rettype)
00050 #else
00051 # define CHECK_RET_CONST_LDOUBLE(func, rettype) \
00052   CHECK_RET_CONST_TYPE (func, rettype, lx, long double)
00053 #endif
00054 
00055 #define CHECK_RET_CONST(func, rettype) \
00056 static void                                                          \
00057 check_return_ ##func (void)                                          \
00058 {                                                                    \
00059   CHECK_RET_CONST_FLOAT (func, rettype)                                     \
00060   CHECK_RET_CONST_DOUBLE (func, rettype)                             \
00061   CHECK_RET_CONST_LDOUBLE (func, rettype)                            \
00062 }
00063 
00064 CHECK_RET_CONST(ilogb, int)
00065 CHECK_RET_CONST(lrint, long)
00066 CHECK_RET_CONST(lround, long)
00067 CHECK_RET_CONST(llrint, long long)
00068 CHECK_RET_CONST(llround, long long)
00069 
00070 static int
00071 do_test (void)
00072 {
00073   check_return_ilogb ();
00074   check_return_lrint ();
00075   check_return_lround ();
00076   check_return_llrint ();
00077   check_return_llround ();
00078 
00079   printf ("%Zd\n", sizeof(carg (lx)));
00080 
00081   return errors != 0;
00082 }
00083 
00084 #define TEST_FUNCTION do_test ()
00085 #include "../test-skeleton.c"