2 * copyright (c) 2016 Ganesh Ajjanagadde <gajjanag@gmail.com>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * internal math functions header
26 #ifndef AVUTIL_FFMATH_H
27 #define AVUTIL_FFMATH_H
29 #include "attributes.h"
33 * Compute 10^x for floating point values. Note: this function is by no means
34 * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
35 * For instance, maximum relative error for the double precision variant is
36 * ~ 1e-13 for very small and very large values.
37 * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
42 static av_always_inline double ff_exp10(double x)
44 return exp2(M_LOG2_10 * x);
47 static av_always_inline float ff_exp10f(float x)
49 return exp2f(M_LOG2_10 * x);
53 * Compute x^y for floating point x, y. Note: this function is faster than the
54 * libm variant due to mainly 2 reasons:
55 * 1. It does not handle any edge cases. In particular, this is only guaranteed
56 * to work correctly for x > 0.
57 * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
62 static av_always_inline float ff_fast_powf(float x, float y)
64 return expf(logf(x) * y);
67 #endif /* AVUTIL_FFMATH_H */