Coverage Report

Created: 2026-10-28 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavutil/ffmath.h
Line
Count
Source
1
/*
2
 * copyright (c) 2016 Ganesh Ajjanagadde <gajjanag@gmail.com>
3
 *
4
 * This file is part of FFmpeg.
5
 *
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.
10
 *
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.
15
 *
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
19
 */
20
21
/**
22
 * @file
23
 * internal math functions header
24
 */
25
26
#ifndef AVUTIL_FFMATH_H
27
#define AVUTIL_FFMATH_H
28
29
#include <math.h>
30
31
#include "attributes.h"
32
#include "mathematics.h"
33
34
/**
35
 * Compute 10^x for floating point values. Note: this function is by no means
36
 * "correctly rounded", and is meant as a fast, reasonably accurate approximation.
37
 * For instance, maximum relative error for the double precision variant is
38
 * ~ 1e-13 for very small and very large values.
39
 * This is ~2x faster than GNU libm's approach, which is still off by 2ulp on
40
 * some inputs.
41
 * @param x exponent
42
 * @return 10^x
43
 */
44
static av_always_inline double ff_exp10(double x)
45
0
{
46
0
    return exp2(M_LOG2_10 * x);
47
0
}
48
49
static av_always_inline float ff_exp10f(float x)
50
0
{
51
0
    return exp2f(M_LOG2_10 * x);
52
0
}
53
54
/**
55
 * Compute x^y for floating point x, y. Note: this function is faster than the
56
 * libm variant due to mainly 2 reasons:
57
 * 1. It does not handle any edge cases. In particular, this is only guaranteed
58
 * to work correctly for x > 0.
59
 * 2. It is not as accurate as a standard nearly "correctly rounded" libm variant.
60
 * @param x base
61
 * @param y exponent
62
 * @return x^y
63
 */
64
static av_always_inline float ff_fast_powf(float x, float y)
65
0
{
66
0
    return expf(logf(x) * y);
67
0
}
68
69
#endif /* AVUTIL_FFMATH_H */