forked from rpavlik/StandardCplusplus
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcmath
More file actions
479 lines (416 loc) · 8.63 KB
/
cmath
File metadata and controls
479 lines (416 loc) · 8.63 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
/* Copyright (C) 2006 Garrett A. Kajmowicz
This file is part of the uClibc++ Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <math.h>
#ifndef __STD_HEADER_CMATH
#define __STD_HEADER_CMATH 1
# undef abs
# undef acos
# undef asin
# undef atan
# undef atan2
# undef ceil
# undef cos
# undef cosh
# undef exp
# undef fabs
# undef floor
# undef fmod
# undef frexp
# undef ldexp
# undef log
# undef log10
# undef modf
# undef pow
# undef sin
# undef sinh
# undef sqrt
# undef tan
# undef tanh
// Workaround for older (at least pre-1.8.0) versions of avr-libc's copy
// of math.h - on that platform doubles and floats are interchangeable.
# if defined(__AVR__) && __SIZEOF_FLOAT__ == __SIZEOF_DOUBLE__
# ifndef fabsf
# define fabsf fabs
# define WORKAROUND_fabs
# endif
# ifndef acosf
# define acosf acos
# define WORKAROUND_acos
# endif
# ifndef asinf
# define asinf asin
# define WORKAROUND_asin
# endif
# ifndef atanf
# define atanf atan
# define WORKAROUND_atan
# endif
# ifndef atan2f
# define atan2f atan2
# define WORKAROUND_atan2
# endif
# ifndef ceilf
# define ceilf ceil
# define WORKAROUND_ceil
# endif
# ifndef cosf
# define cosf cos
# define WORKAROUND_cos
# endif
# ifndef coshf
# define coshf cosh
# define WORKAROUND_cosh
# endif
# ifndef expf
# define expf exp
# define WORKAROUND_exp
# endif
# ifndef fabsf
# define fabsf fabs
# define WORKAROUND_fabs
# endif
# ifndef floorf
# define floorf floor
# define WORKAROUND_floor
# endif
# ifndef fmodf
# define fmodf fmod
# define WORKAROUND_fmod
# endif
# ifndef frexpf
# define frexpf frexp
# define WORKAROUND_frexp
# endif
# ifndef ldexpf
# define ldexpf ldexp
# define WORKAROUND_ldexp
# endif
# ifndef logf
# define logf log
# define WORKAROUND_log
# endif
# ifndef log10f
# define log10f log10
# define WORKAROUND_log10
# endif
# ifndef modff
# define WORKAROUND_modf
# endif
# ifndef powf
# define powf pow
# define WORKAROUND_pow
# endif
# ifndef sinf
# define sinf sin
# define WORKAROUND_sin
# endif
# ifndef sinhf
# define sinhf sinh
# define WORKAROUND_sinh
# endif
# ifndef sqrtf
# define sqrtf sqrt
# define WORKAROUND_sqrt
# endif
# ifndef tanf
# define tanf tan
# define WORKAROUND_tan
# endif
# ifndef tanhf
# define tanhf tanh
# define WORKAROUND_tanh
# endif
# endif // AVR workaround
namespace std {
using ::acos;
using ::asin;
using ::atan;
using ::atan2;
using ::ceil;
using ::cos;
using ::cosh;
using ::exp;
using ::fabs;
using ::floor;
using ::fmod;
using ::frexp;
using ::ldexp;
using ::log;
using ::log10;
using ::modf;
using ::pow;
using ::sin;
using ::sinh;
using ::sqrt;
using ::tan;
using ::tanh;
# ifndef __CORRECT_ISO_CPP_MATH_H_PROTO
inline float abs (float x){
return ::fabsf(x);
}
inline float acos (float x){
return ::acosf(x);
}
inline float asin (float x){
return ::asinf(x);
}
inline float atan (float x){
return ::atanf(x);
}
inline float atan2(float y, float x){
return ::atan2f(y, x);
}
inline float ceil (float x){
return ::ceilf(x);
}
inline float cos (float x){
return ::cosf(x);
}
inline float cosh (float x){
return ::coshf(x);
}
inline float exp (float x){
return ::expf(x);
}
inline float fabs (float x){
return ::fabsf(x);
}
inline float floor(float x){
return ::floorf(x);
}
inline float fmod (float x, float y){
return ::fmodf(x, y);
}
inline float frexp(float x, int* exp){
return ::frexpf(x, exp);
}
inline float ldexp(float x, int exp){
return ::ldexpf(x, exp);
}
inline float log (float x){
return ::logf(x);
}
inline float log10(float x){
return ::log10f(x);
}
inline float modf (float x, float* inptr){
# ifdef WORKAROUND_modf
double intpart;
float ret = static_cast<float>(::modf(static_cast<double>(x), & intpart));
*inptr = static_cast<float>(intpart);
return ret;
# else
return ::modff(x, inptr);
# endif
}
inline float pow (float x, float y){
return ::powf(x, y);
}
# if 1 // DR 550 removed this
inline float pow (float x, int y){
return ::pow((double)x, (double)y);
}
# endif
inline float sin (float x){
return ::sinf(x);
}
inline float sinh (float x){
return ::sinhf(x);
}
inline float sqrt (float x){
return ::sqrtf(x);
}
inline float tan (float x){
return ::tanf(x);
}
inline float tanh (float x){
return ::tanhf(x);
}
inline double abs(double x){
return ::fabs(x);
}
inline double pow(double x, int y){
return ::pow((double)x, (double)y);
}
# ifdef __UCLIBCXX_HAS_LONG_DOUBLE__
inline long double abs (long double x){
return ::fabsl(x);
}
inline long double acos (long double x){
return ::acosl(x);
}
inline long double asin (long double x){
return ::asinl(x);
}
inline long double atan (long double x){
return ::atanl(x);
}
inline long double atan2(long double y, long double x){
return ::atan2l(y, x);
}
inline long double ceil (long double x){
return ::ceill(x);
}
inline long double cos (long double x){
return ::cosl(x);
}
inline long double cosh (long double x){
return ::coshl(x);
}
inline long double exp (long double x){
return ::expl(x);
}
inline long double fabs (long double x){
return ::fabsl(x);
}
inline long double floor(long double x){
return ::floorl(x);
}
inline long double frexp(long double x, int* exp){
return ::frexpl(x, exp);
}
inline long double fmod (long double x, long double y){
return ::fmodl(x, y);
}
inline long double ldexp(long double x, int y){
return ::ldexpl(x, y);
}
inline long double log (long double x){
return ::logl(x);
}
inline long double log10(long double x){
return ::log10l(x);
}
inline long double modf (long double x, long double* iptr){
return ::modfl(x, iptr);
}
inline long double pow (long double x, long double y){
return ::powl(x, y);
}
inline long double pow (long double x, int y){
return ::powl(x, (long double)y );
}
inline long double sin (long double x){
return ::sinl(x);
}
inline long double sinh (long double x){
return ::sinhl(x);
}
inline long double sqrt (long double x){
return ::sqrtl(x);
}
inline long double tan (long double x){
return ::tanl(x);
}
inline long double tanh (long double x){
return ::tanhl(x);
}
# endif // __UCLIBCXX_HAS_LONG_DOUBLE__
# endif // __CORRECT_ISO_CPP_MATH_H_PROTO
}
// Undo AVR workaround, if applied
# ifdef WORKAROUND_fabs
# undef fabsf
# undef WORKAROUND_fabs
# endif
# ifdef WORKAROUND_acos
# undef acosf
# undef WORKAROUND_acos
# endif
# ifdef WORKAROUND_asin
# undef asinf
# undef WORKAROUND_asin
# endif
# ifdef WORKAROUND_atan
# undef atanf
# undef WORKAROUND_atan
# endif
# ifdef WORKAROUND_atan2
# undef atan2f
# undef WORKAROUND_atan2
# endif
# ifdef WORKAROUND_ceil
# undef ceilf
# undef WORKAROUND_ceil
# endif
# ifdef WORKAROUND_cos
# undef cosf
# undef WORKAROUND_cos
# endif
# ifdef WORKAROUND_cosh
# undef coshf
# undef WORKAROUND_cosh
# endif
# ifdef WORKAROUND_exp
# undef expf
# undef WORKAROUND_exp
# endif
# ifdef WORKAROUND_fabs
# undef fabsf
# undef WORKAROUND_fabs
# endif
# ifdef WORKAROUND_floor
# undef floorf
# undef WORKAROUND_floor
# endif
# ifdef WORKAROUND_fmod
# undef fmodf
# undef WORKAROUND_fmod
# endif
# ifdef WORKAROUND_frexp
# undef frexpf
# undef WORKAROUND_frexp
# endif
# ifdef WORKAROUND_ldexp
# undef ldexpf
# undef WORKAROUND_ldexp
# endif
# ifdef WORKAROUND_log
# undef logf
# undef WORKAROUND_log
# endif
# ifdef WORKAROUND_log10
# undef log10f
# undef WORKAROUND_log10
# endif
# ifdef WORKAROUND_modf
# undef modff
# undef WORKAROUND_modf
# endif
# ifdef WORKAROUND_pow
# undef powf
# undef WORKAROUND_pow
# endif
# ifdef WORKAROUND_sin
# undef sinf
# undef WORKAROUND_sin
# endif
# ifdef WORKAROUND_sinh
# undef sinhf
# undef WORKAROUND_sinh
# endif
# ifdef WORKAROUND_sqrt
# undef sqrtf
# undef WORKAROUND_sqrt
# endif
# ifdef WORKAROUND_tan
# undef tanf
# undef WORKAROUND_tan
# endif
# ifdef WORKAROUND_tanh
# undef tanhf
# undef WORKAROUND_tanh
# endif
#endif //__STD_HEADER_CMATH