2 * This file is part of Libav.
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.
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.
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
21 * Replacements for frequently missing libm functions
29 #include "attributes.h"
33 static av_always_inline
float cbrtf(float x
)
35 return x
< 0 ?
-powf(-x
, 1.0 / 3.0) : powf(x
, 1.0 / 3.0);
41 #define exp2(x) exp((x) * 0.693147180559945)
42 #endif /* HAVE_EXP2 */
46 #define exp2f(x) ((float)exp2(x))
47 #endif /* HAVE_EXP2F */
50 static av_always_inline av_const
int isinf(float x
)
52 uint32_t v
= av_float2int(x
);
53 if ((v
& 0x7f800000) != 0x7f800000)
55 return !(v
& 0x007fffff);
57 #endif /* HAVE_ISINF */
60 static av_always_inline av_const
int isnan(float x
)
62 uint32_t v
= av_float2int(x
);
63 if ((v
& 0x7f800000) != 0x7f800000)
65 return v
& 0x007fffff;
67 #endif /* HAVE_ISNAN */
71 #define llrint(x) ((long long)rint(x))
72 #endif /* HAVE_LLRINT */
76 #define llrintf(x) ((long long)rint(x))
77 #endif /* HAVE_LLRINT */
81 #define log2(x) (log(x) * 1.44269504088896340736)
82 #endif /* HAVE_LOG2 */
86 #define log2f(x) ((float)log2(x))
87 #endif /* HAVE_LOG2F */
90 static av_always_inline av_const
long int lrint(double x
)
94 #endif /* HAVE_LRINT */
97 static av_always_inline av_const
long int lrintf(float x
)
99 return (int)(rint(x
));
101 #endif /* HAVE_LRINTF */
104 static av_always_inline av_const
double round(double x
)
106 return (x
> 0) ?
floor(x
+ 0.5) : ceil(x
- 0.5);
108 #endif /* HAVE_ROUND */
111 static av_always_inline av_const
float roundf(float x
)
113 return (x
> 0) ?
floor(x
+ 0.5) : ceil(x
- 0.5);
115 #endif /* HAVE_ROUNDF */
118 static av_always_inline av_const
double trunc(double x
)
120 return (x
> 0) ?
floor(x
) : ceil(x
);
122 #endif /* HAVE_TRUNC */
125 static av_always_inline av_const
float truncf(float x
)
127 return (x
> 0) ?
floor(x
) : ceil(x
);
129 #endif /* HAVE_TRUNCF */
131 #endif /* AVUTIL_LIBM_H */