[FFmpeg-devel] [PATCH] all: use predefined mathematics macros

Ganesh Ajjanagadde gajjanagadde at gmail.com
Wed Nov 11 14:39:02 CET 2015


On Wed, Nov 11, 2015 at 3:28 AM, Paul B Mahol <onemda at gmail.com> wrote:
> On 11/11/15, Ganesh Ajjanagadde <gajjanagadde at gmail.com> wrote:
>> This uses M_SQRT2, M_PI, and M_E instead of the actual literals.
>> Benefits include:
>> 1. Reduced scope for copy/paste errors and improved readability.
>> 2. Consistency across the codebase.
>> 3. Actually fixes an incorrect sqrt(2) in avcodec/ppc.
>> 4. Greater precision in avcodec/ac3.
>>
>> Patch tested with FATE on x86, ppc untested.
>>
>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>> ---
>>  libavcodec/ac3.h                   |  2 +-
>>  libavcodec/cos_tablegen.c          |  4 +++-
>>  libavcodec/mpegaudioenc_template.c |  4 ++--
>>  libavcodec/mpegaudiotab.h          |  2 --
>>  libavcodec/mpegvideo.c             |  4 ++--
>>  libavcodec/ppc/fdctdsp.c           | 21 ++++++++++-----------
>>  libavcodec/ratecontrol.c           |  4 ----
>>  libavcodec/simple_idct.c           |  4 ++--
>>  libavfilter/af_dynaudnorm.c        |  4 +---
>>  9 files changed, 21 insertions(+), 28 deletions(-)
>>
>
> [...]
>
>> diff --git a/libavfilter/af_dynaudnorm.c b/libavfilter/af_dynaudnorm.c
>> index 8f0c2d0..62a2653 100644
>> --- a/libavfilter/af_dynaudnorm.c
>> +++ b/libavfilter/af_dynaudnorm.c
>> @@ -227,8 +227,6 @@ static int cqueue_pop(cqueue *q)
>>      return 0;
>>  }
>>
>> -static const double s_pi =
>> 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679;
>> -
>>  static void init_gaussian_filter(DynamicAudioNormalizerContext *s)
>>  {
>>      double total_weight = 0.0;
>> @@ -238,7 +236,7 @@ static void
>> init_gaussian_filter(DynamicAudioNormalizerContext *s)
>>
>>      // Pre-compute constants
>>      const int offset = s->filter_size / 2;
>> -    const double c1 = 1.0 / (sigma * sqrt(2.0 * s_pi));
>> +    const double c1 = 1.0 / (sigma * sqrt(2.0 * M_PI));
>
> Please leave this one as it is.

I can do this, but please offer a rationale: the "precision" offered
here is highly misleading - all those digits will anyway be truncated
down to M_PI. If you really care about this precision, a long double
should be used instead, and likewise sqrtl instead of sqrt.

>
>>      const double c2 = 2.0 * pow(sigma, 2.0);
>>
>>      // Compute weights


More information about the ffmpeg-devel mailing list