]> git.sesse.net Git - ffmpeg/blob - libavutil/libm.h
nut: support pcm codecs not mapped in avi
[ffmpeg] / libavutil / libm.h
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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 #include "intfloat.h"
31
32 #if !HAVE_CBRTF
33 static av_always_inline float cbrtf(float x)
34 {
35     return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
36 }
37 #endif
38
39 #if !HAVE_EXP2
40 #undef exp2
41 #define exp2(x) exp((x) * 0.693147180559945)
42 #endif /* HAVE_EXP2 */
43
44 #if !HAVE_EXP2F
45 #undef exp2f
46 #define exp2f(x) ((float)exp2(x))
47 #endif /* HAVE_EXP2F */
48
49 #if !HAVE_ISINF
50 static av_always_inline av_const int isinf(float x)
51 {
52     uint32_t v = av_float2int(x);
53     if ((v & 0x7f800000) != 0x7f800000)
54         return 0;
55     return !(v & 0x007fffff);
56 }
57 #endif /* HAVE_ISINF */
58
59 #if !HAVE_ISNAN
60 static av_always_inline av_const int isnan(float x)
61 {
62     uint32_t v = av_float2int(x);
63     if ((v & 0x7f800000) != 0x7f800000)
64         return 0;
65     return v & 0x007fffff;
66 }
67 #endif /* HAVE_ISNAN */
68
69 #if !HAVE_LLRINT
70 #undef llrint
71 #define llrint(x) ((long long)rint(x))
72 #endif /* HAVE_LLRINT */
73
74 #if !HAVE_LLRINTF
75 #undef llrintf
76 #define llrintf(x) ((long long)rint(x))
77 #endif /* HAVE_LLRINT */
78
79 #if !HAVE_LOG2
80 #undef log2
81 #define log2(x) (log(x) * 1.44269504088896340736)
82 #endif /* HAVE_LOG2 */
83
84 #if !HAVE_LOG2F
85 #undef log2f
86 #define log2f(x) ((float)log2(x))
87 #endif /* HAVE_LOG2F */
88
89 #if !HAVE_RINT
90 static inline double rint(double x)
91 {
92     return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
93 }
94 #endif /* HAVE_RINT */
95
96 #if !HAVE_LRINT
97 static av_always_inline av_const long int lrint(double x)
98 {
99     return rint(x);
100 }
101 #endif /* HAVE_LRINT */
102
103 #if !HAVE_LRINTF
104 static av_always_inline av_const long int lrintf(float x)
105 {
106     return (int)(rint(x));
107 }
108 #endif /* HAVE_LRINTF */
109
110 #if !HAVE_ROUND
111 static av_always_inline av_const double round(double x)
112 {
113     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
114 }
115 #endif /* HAVE_ROUND */
116
117 #if !HAVE_ROUNDF
118 static av_always_inline av_const float roundf(float x)
119 {
120     return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
121 }
122 #endif /* HAVE_ROUNDF */
123
124 #if !HAVE_TRUNC
125 static av_always_inline av_const double trunc(double x)
126 {
127     return (x > 0) ? floor(x) : ceil(x);
128 }
129 #endif /* HAVE_TRUNC */
130
131 #if !HAVE_TRUNCF
132 static av_always_inline av_const float truncf(float x)
133 {
134     return (x > 0) ? floor(x) : ceil(x);
135 }
136 #endif /* HAVE_TRUNCF */
137
138 #endif /* AVUTIL_LIBM_H */