]> git.sesse.net Git - ffmpeg/blob - libavutil/libm.h
Merge remote-tracking branch 'qatar/master'
[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_MIPSFPU && HAVE_INLINE_ASM
32 #include "libavutil/mips/libm_mips.h"
33 #endif /* HAVE_MIPSFPU && HAVE_INLINE_ASM*/
34
35 #if !HAVE_CBRTF
36 #undef cbrtf
37 #define cbrtf(x) powf(x, 1.0/3.0)
38 #endif /* HAVE_CBRTF */
39
40 #if !HAVE_EXP2
41 #undef exp2
42 #define exp2(x) exp((x) * 0.693147180559945)
43 #endif /* HAVE_EXP2 */
44
45 #if !HAVE_EXP2F
46 #undef exp2f
47 #define exp2f(x) ((float)exp2(x))
48 #endif /* HAVE_EXP2F */
49
50 #if !HAVE_LLRINT
51 #undef llrint
52 #define llrint(x) ((long long)rint(x))
53 #endif /* HAVE_LLRINT */
54
55 #if !HAVE_LLRINTF
56 #undef llrintf
57 #define llrintf(x) ((long long)rint(x))
58 #endif /* HAVE_LLRINT */
59
60 #if !HAVE_LOG2
61 #undef log2
62 #define log2(x) (log(x) * 1.44269504088896340736)
63 #endif /* HAVE_LOG2 */
64
65 #if !HAVE_LOG2F
66 #undef log2f
67 #define log2f(x) ((float)log2(x))
68 #endif /* HAVE_LOG2F */
69
70 #if !HAVE_LRINT
71 static av_always_inline av_const long int lrint(double x)
72 {
73     return rint(x);
74 }
75 #endif /* HAVE_LRINT */
76
77 #if !HAVE_LRINTF
78 static av_always_inline av_const long int lrintf(float x)
79 {
80     return (int)(rint(x));
81 }
82 #endif /* HAVE_LRINTF */
83
84 #if !HAVE_ROUND
85 static av_always_inline av_const double round(double x)
86 {
87     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
88 }
89 #endif /* HAVE_ROUND */
90
91 #if !HAVE_ROUNDF
92 static av_always_inline av_const float roundf(float x)
93 {
94     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
95 }
96 #endif /* HAVE_ROUNDF */
97
98 #if !HAVE_TRUNC
99 static av_always_inline av_const double trunc(double x)
100 {
101     return (x > 0) ? floor(x) : ceil(x);
102 }
103 #endif /* HAVE_TRUNC */
104
105 #if !HAVE_TRUNCF
106 static av_always_inline av_const float truncf(float x)
107 {
108     return (x > 0) ? floor(x) : ceil(x);
109 }
110 #endif /* HAVE_TRUNCF */
111
112 #endif /* AVUTIL_LIBM_H */