[FFmpeg-devel] [PATCHv2] lavc/aacenc_utils: replace powf(x, y) by expf(logf(x), y)

Ronald S. Bultje rsbultje at gmail.com
Sun Mar 13 12:51:58 CET 2016


Hi,

On Sat, Mar 12, 2016 at 11:40 AM, Ganesh Ajjanagadde <gajjanag at gmail.com>
wrote:

> diff --git a/libavutil/internal.h b/libavutil/internal.h
> index da76ca2..aa43754 100644
> --- a/libavutil/internal.h
> +++ b/libavutil/internal.h
> @@ -315,6 +315,22 @@ static av_always_inline float ff_exp10f(float x)
>  }
>
>  /**
> + * Compute x^y for floating point x, y. Note: this function is faster
> than the
> + * libm variant due to mainly 2 reasons:
> + * 1. It does not handle any edge cases. In particular, this is only
> guaranteed
> + * to work correctly for x > 0.
> + * 2. It is not as accurate as a standard nearly "correctly rounded" libm
> variant.
> + * @param x base
> + * @param y exponent
> + * @return x^y
> + */
> +static av_always_inline float ff_fast_pow(float x, float y)
> +{
> +    return expf(logf(x) * y);
> +}


Thanks, mostly OK. Small comments:

- I wonder if this should move to a separate file, e.g. it seems more
fitting in mathematics.h or libm.h. internal.h seems like a strange choice.
I don't know which is better, I'd personally probably go for libm.h but I
can see why some people wouldn't like it since it slightly changes the
meaning of that file.
- it should be called ff_fast_powf since it's float-based, not double-based
(compare pow vs. powf)

(I also noticed there are some huge huge huge functions in libm.h that
probably shouldn't be in a header but move to a .c file instead, if anyone
is looking for a cleanup target - e.g. hypoth and erf.)

Ronald


More information about the ffmpeg-devel mailing list