Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
MATH_OVERLOADS.cpp
Go to the documentation of this file.
1// checking for function overloads in <math.h>
2
3
25#include <math.h>
26#include <stdio.h>
27
28#include "config.h"
29
30
31const char* type_name (float) { return "FLT"; }
32const char* type_name (double) { return "DBL"; }
33const char* type_name (long double) { return "LDBL"; }
34
35
36// define function templates with the same signatures as
37// the required overloads; if the required overloads are
38// not defined, the corresponding specializations of the
39// function templates will be instantiated and called,
40// and will print the appropriate config macros;
41// otherwise the macros are not printed/#defined
42
43#define FUN_1(name, NAME) \
44 template <class T> \
45 T name (T) { \
46 return printf ("#define _RWSTD_NO_%s_%s\n", \
47 NAME, type_name (T ())); \
48 } typedef void unused_typedef
49
50#define FUN_2(name, NAME) \
51 template <class T> \
52 T name (T, T) { \
53 return printf ("#define _RWSTD_NO_%s_%s\n", \
54 NAME, type_name (T ())); \
55 } typedef void unused_typedef
56
57#define FUN_2_PTR(name, NAME) \
58 template <class T> \
59 T name (T, T*) { \
60 return printf ("#define _RWSTD_NO_%s_%s\n", \
61 NAME, type_name (T ())); \
62 } typedef void unused_typedef
63
64#define FUN_2_INT(name, NAME) \
65 template <class T> \
66 T name (T, int) { \
67 return printf ("#define _RWSTD_NO_%s_%s_INT\n", \
68 NAME, type_name (T ())); \
69 } typedef void unused_typedef
70
71#define FUN_2_PINT(name, NAME) \
72 template <class T> \
73 T name (T, int*) { \
74 return printf ("#define _RWSTD_NO_%s_%s\n", \
75 NAME, type_name (T ())); \
76 } typedef void unused_typedef
77
78
79// abs() is not declared in the C header <math.h> but is required
80// to be declared in the C++ headers <math.h> and <cmath>
81FUN_1 (abs, "ABS");
82FUN_1 (acos, "ACOS");
83FUN_1 (asin, "ASIN");
84FUN_1 (atan, "ATAN");
85FUN_2 (atan2, "ATAN2");
86FUN_1 (ceil, "CEIL");
87FUN_1 (cos, "COS");
88FUN_1 (cosh, "COSH");
89FUN_1 (exp, "EXP");
90FUN_1 (fabs, "FABS");
91FUN_1 (floor, "FLOOR");
92FUN_2 (fmod, "FMOD");
93FUN_2_PINT (frexp, "FREXP");
94FUN_2_INT (ldexp, "LDEXP");
95FUN_1 (log, "LOG");
96FUN_1 (log10, "LOG10");
97FUN_2_PTR (modf, "MODF");
98FUN_2 (pow, "POW");
99FUN_2_INT (pow, "POW");
100FUN_1 (sin, "SIN");
101FUN_1 (sinh, "SINH");
102FUN_1 (sqrt, "SQRT");
103FUN_1 (tan, "TAN");
104FUN_1 (tanh, "TANH");
105
106
107int main ()
108{
109 float f = 0;
110 double d = 0;
111
112#ifndef _RWSTD_NO_LONG_DOUBLE
113
114 long double ld = 0;
115
116# define IF_LDBL if (1)
117#else
118
119 double ld = 0;
120
121# define IF_LDBL if (0)
122#endif // _RWSTD_NO_LONG_DOUBLE
123
124 int i = 0;
125
126 abs (d); abs (f); IF_LDBL abs (ld);
127 acos (d); acos (f); IF_LDBL acos (ld);
128 asin (d); asin (f); IF_LDBL asin (ld);
129 atan (d); atan (f); IF_LDBL atan (ld);
130 atan2 (d, d); atan2 (f, f); IF_LDBL atan2 (ld, ld);
131 ceil (d); ceil (f); IF_LDBL ceil (ld);
132 cos (d); cos (f); IF_LDBL cos (ld);
133 cosh (d); cosh (f); IF_LDBL cosh (ld);
134 exp (d); exp (f); IF_LDBL exp (ld);
135 fabs (d); fabs (f); IF_LDBL fabs (ld);
136 floor (d); floor (f); IF_LDBL floor (ld);
137 fmod (d, d); fmod (f, f); IF_LDBL fmod (ld, ld);
138 frexp (d, &i); frexp (f, &i); IF_LDBL frexp (ld, &i);
139 ldexp (d, i); ldexp (f, i); IF_LDBL ldexp (ld, i);
140 log (d); log (f); IF_LDBL log (ld);
141 log10 (d); log10 (f); IF_LDBL log10 (ld);
142 modf (d, &d); modf (f, &f); IF_LDBL modf (ld, &ld);
143 pow (d, d); pow (f, f); IF_LDBL pow (ld, ld);
144 pow (d, i); pow (f, i); IF_LDBL pow (ld, i);
145 sin (d); sin (f); IF_LDBL sin (ld);
146 sinh (d); sinh (f); IF_LDBL sinh (ld);
147 sqrt (d); sqrt (f); IF_LDBL sqrt (ld);
148 tan (d); tan (f); IF_LDBL tan (ld);
149 tanh (d); tanh (f); IF_LDBL tanh (ld);
150
151 return 0;
152}
#define i
Definition 17.names.cpp:126
#define d
Definition 17.names.cpp:115
#define f
Definition 17.names.cpp:119
const char * type_name()
T abs(T t)
#define FUN_2_PINT(name, NAME)
#define FUN_1(name, NAME)
#define IF_LDBL
#define FUN_2(name, NAME)
#define FUN_2_PTR(name, NAME)
int main()
#define FUN_2_INT(name, NAME)