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*/
37 static av_always_inline float cbrtf(float x)
39 return x < 0 ? -powf(-x, 1.0 / 3.0) : powf(x, 1.0 / 3.0);
45 #define exp2(x) exp((x) * 0.693147180559945)
46 #endif /* HAVE_EXP2 */
50 #define exp2f(x) ((float)exp2(x))
51 #endif /* HAVE_EXP2F */
54 static av_always_inline av_const int isinf(float x)
56 uint32_t v = av_float2int(x);
57 if ((v & 0x7f800000) != 0x7f800000)
59 return !(v & 0x007fffff);
61 #endif /* HAVE_ISINF */
64 static av_always_inline av_const int isnan(float x)
66 uint32_t v = av_float2int(x);
67 if ((v & 0x7f800000) != 0x7f800000)
69 return v & 0x007fffff;
71 #endif /* HAVE_ISNAN */
75 #define llrint(x) ((long long)rint(x))
76 #endif /* HAVE_LLRINT */
80 #define llrintf(x) ((long long)rint(x))
81 #endif /* HAVE_LLRINT */
85 #define log2(x) (log(x) * 1.44269504088896340736)
86 #endif /* HAVE_LOG2 */
90 #define log2f(x) ((float)log2(x))
91 #endif /* HAVE_LOG2F */
94 static inline double rint(double x)
96 return x >= 0 ? floor(x + 0.5) : ceil(x - 0.5);
98 #endif /* HAVE_RINT */
101 static av_always_inline av_const long int lrint(double x)
105 #endif /* HAVE_LRINT */
108 static av_always_inline av_const long int lrintf(float x)
110 return (int)(rint(x));
112 #endif /* HAVE_LRINTF */
115 static av_always_inline av_const double round(double x)
117 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
119 #endif /* HAVE_ROUND */
122 static av_always_inline av_const float roundf(float x)
124 return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5);
126 #endif /* HAVE_ROUNDF */
129 static av_always_inline av_const double trunc(double x)
131 return (x > 0) ? floor(x) : ceil(x);
133 #endif /* HAVE_TRUNC */
136 static av_always_inline av_const float truncf(float x)
138 return (x > 0) ? floor(x) : ceil(x);
140 #endif /* HAVE_TRUNCF */
142 #endif /* AVUTIL_LIBM_H */