2 * This file is part of FFmpeg.
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.
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.
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
21 * Replacements for frequently missing libm functions
29 #include "attributes.h"
32 #if HAVE_MIPSFPU && HAVE_INLINE_ASM
33 #include "libavutil/mips/libm_mips.h"
34 #endif /* HAVE_MIPSFPU && HAVE_INLINE_ASM*/
38 #define atanf(x) ((float)atan(x))
43 #define atan2f(y, x) ((float)atan2(y, x))
48 #define powf(x, y) ((float)pow(x, y))
52 static av_always_inline float cbrtf(float x)
54 return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
60 #define cosf(x) ((float)cos(x))
65 #define expf(x) ((float)exp(x))
70 #define exp2(x) exp((x) * 0.693147180559945)
71 #endif /* HAVE_EXP2 */
75 #define exp2f(x) ((float)exp2(x))
76 #endif /* HAVE_EXP2F */
79 static av_always_inline av_const int isinf(float x)
81 uint32_t v = av_float2int(x);
82 if ((v & 0x7f800000) != 0x7f800000)
84 return !(v & 0x007fffff);
86 #endif /* HAVE_ISINF */
89 static av_always_inline av_const int isnan(float x)
91 uint32_t v = av_float2int(x);
92 if ((v & 0x7f800000) != 0x7f800000)
94 return v & 0x007fffff;
96 #endif /* HAVE_ISNAN */
100 #define ldexpf(x, exp) ((float)ldexp(x, exp))
105 #define llrint(x) ((long long)rint(x))
106 #endif /* HAVE_LLRINT */
110 #define llrintf(x) ((long long)rint(x))
111 #endif /* HAVE_LLRINT */
115 #define log2(x) (log(x) * 1.44269504088896340736)
116 #endif /* HAVE_LOG2 */
120 #define log2f(x) ((float)log2(x))
121 #endif /* HAVE_LOG2F */
125 #define log10f(x) ((float)log10(x))
130 #define sinf(x) ((float)sin(x))
134 static inline double rint(double x)
136 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
138 #endif /* HAVE_RINT */
141 static av_always_inline av_const long int lrint(double x)
145 #endif /* HAVE_LRINT */
148 static av_always_inline av_const long int lrintf(float x)
150 return (int)(rint(x));
152 #endif /* HAVE_LRINTF */
155 static av_always_inline av_const double round(double x)
157 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
159 #endif /* HAVE_ROUND */
162 static av_always_inline av_const float roundf(float x)
164 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
166 #endif /* HAVE_ROUNDF */
169 static av_always_inline av_const double trunc(double x)
171 return (x > 0) ? floor(x) : ceil(x);
173 #endif /* HAVE_TRUNC */
176 static av_always_inline av_const float truncf(float x)
178 return (x > 0) ? floor(x) : ceil(x);
180 #endif /* HAVE_TRUNCF */
182 #endif /* AVUTIL_LIBM_H */