]> git.sesse.net Git - ffmpeg/blob - libavutil/libm.h
Merge remote-tracking branch 'richardpl/escape130'
[ffmpeg] / libavutil / libm.h
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 /**
20  * @file
21  * Replacements for frequently missing libm functions
22  */
23
24 #ifndef AVUTIL_LIBM_H
25 #define AVUTIL_LIBM_H
26
27 #include <math.h>
28 #include "config.h"
29 #include "attributes.h"
30
31 #if !HAVE_CBRTF
32 #undef cbrtf
33 #define cbrtf(x) powf(x, 1.0/3.0)
34 #endif /* HAVE_CBRTF */
35
36 #if !HAVE_EXP2
37 #undef exp2
38 #define exp2(x) exp((x) * 0.693147180559945)
39 #endif /* HAVE_EXP2 */
40
41 #if !HAVE_EXP2F
42 #undef exp2f
43 #define exp2f(x) ((float)exp2(x))
44 #endif /* HAVE_EXP2F */
45
46 #if !HAVE_LLRINT
47 #undef llrint
48 #define llrint(x) ((long long)rint(x))
49 #endif /* HAVE_LLRINT */
50
51 #if !HAVE_LLRINTF
52 #undef llrintf
53 #define llrintf(x) ((long long)rint(x))
54 #endif /* HAVE_LLRINT */
55
56 #if !HAVE_LOG2
57 #undef log2
58 #define log2(x) (log(x) * 1.44269504088896340736)
59 #endif /* HAVE_LOG2 */
60
61 #if !HAVE_LOG2F
62 #undef log2f
63 #define log2f(x) ((float)log2(x))
64 #endif /* HAVE_LOG2F */
65
66 #if !HAVE_LRINT
67 static av_always_inline av_const long int lrint(double x)
68 {
69     return rint(x);
70 }
71 #endif /* HAVE_LRINT */
72
73 #if !HAVE_LRINTF
74 static av_always_inline av_const long int lrintf(float x)
75 {
76     return (int)(rint(x));
77 }
78 #endif /* HAVE_LRINTF */
79
80 #if !HAVE_ROUND
81 static av_always_inline av_const double round(double x)
82 {
83     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
84 }
85 #endif /* HAVE_ROUND */
86
87 #if !HAVE_ROUNDF
88 static av_always_inline av_const float roundf(float x)
89 {
90     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
91 }
92 #endif /* HAVE_ROUNDF */
93
94 #if !HAVE_TRUNC
95 static av_always_inline av_const double trunc(double x)
96 {
97     return (x > 0) ? floor(x) : ceil(x);
98 }
99 #endif /* HAVE_TRUNC */
100
101 #if !HAVE_TRUNCF
102 static av_always_inline av_const float truncf(float x)
103 {
104     return (x > 0) ? floor(x) : ceil(x);
105 }
106 #endif /* HAVE_TRUNCF */
107
108 #endif /* AVUTIL_LIBM_H */