-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.h
80 lines (70 loc) · 2.32 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* This program is free software; you can redistribute it and/or modify
* it under the terms of version 3 or later of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*! \file common.h
\brief Odd definitions
*/
#ifndef _COMMON_H_
#define _COMMON_H_
#include <math.h>
#if !_GNU_SOURCE && !defined (__attribute__)
/*! \brief GNU C specific attributes, e.g. unused
// */
#define __attribute__(X)
#endif
/*! \brief Safe double error value (and float with a cast)
*/
#if defined(HUGE_VAL)
#define ERR_VAL (-HUGE_VAL)
#else
#define ERR_VAL (-FLT_MAX)
#endif
/*! \brief Macro to extract sign
*/
#ifndef SGN
#define SGN(x) ((x) > 0 ? 1 : -1)
#endif
/*! \brief typedef of signal handler function
*/
#if HAVE_SIGACTION
typedef struct sigaction psighandler;
#elif HAVE_SIGVEC
typedef struct sigvec psighandler;
#else
typedef void(*psighandler) (int);
#endif
/* abs returns unsigned int by definition */
#define Abs(a) ((unsigned int)abs(a))
/* signbit() is used only in a somewhat performance sensitive place
in lib/sigmoid.h. If HAVE_DECL_SIGNBIT is false, maybe we should
work around it there instead of using this */
#if !HAVE_DECL_SIGNBIT
/* copysign() caters for special IEEE 754 numbers */
#define signbit(x) (copysign(1, (x)) < 0)
#endif
/* Do we need to use g_utf8_casefold() for utf8 anywhere? */
#define StrCaseCmp(s1, s2) g_ascii_strcasecmp(s1, s2)
#define StrNCaseCmp(s1, s2, n) g_ascii_strncasecmp(s1, s2, (gsize)n)
/* Avoid new code using strcase functions */
#define strcasecmp strcasecmp_error_use_StrCaseCmp
#define strncasecmp strncasecmp_error_use_StrNCaseCmp
/* Macro to mark paramaters that aren't used in the function */
#ifdef UNUSED
#elif defined(__GNUC__)
# define UNUSED(x) UNUSED_ ## x __attribute__((unused))
#elif defined(_lint)
# define UNUSED(x) /*lint -e{715, 818}*/ _unused_##x
#else
# define UNUSED(x) _unused_##x
#endif
#endif