[FFmpeg-devel] [PATCH 4/4] avcodec/faandct: use more accurate constants

Ganesh Ajjanagadde gajjanag at mit.edu
Sun Nov 15 16:29:16 CET 2015


On Sun, Nov 15, 2015 at 10:10 AM, Ganesh Ajjanagadde <gajjanag at mit.edu> wrote:
> On Fri, Nov 13, 2015 at 6:24 PM, Ganesh Ajjanagadde <gajjanag at mit.edu> wrote:
>> On Fri, Nov 13, 2015 at 6:17 PM, Michael Niedermayer
>> <michael at niedermayer.cc> wrote:
>>> On Fri, Nov 13, 2015 at 11:42:31AM -0500, Ganesh Ajjanagadde wrote:
>>>> This guarantees a "best effort precision".
>>>>
>>>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>>>> ---
>>>>  libavcodec/faandct.c | 29 +++++++++++++----------------
>>>>  1 file changed, 13 insertions(+), 16 deletions(-)
>>>>
>>>> diff --git a/libavcodec/faandct.c b/libavcodec/faandct.c
>>>> index 473bc1d..c8ea328 100644
>>>> --- a/libavcodec/faandct.c
>>>> +++ b/libavcodec/faandct.c
>>>> @@ -31,23 +31,20 @@
>>>>
>>>>  typedef float FLOAT;
>>>>
>>>> -//numbers generated by simple c code (not as accurate as they could be)
>>>> -/*
>>>> -for(i=0; i<8; i++){
>>>> -    printf("#define B%d %1.20llf\n", i, (long double)1.0/(cosl(i*acosl(-1.0)/(long double)16.0)*sqrtl(2)));
>>>> -}
>>>> +/* numbers generated by arbitrary precision arithmetic followed by truncation
>>>> +to 36 fractional digits (enough for a 128-bit IEEE quad, see /usr/include/math.h
>>>> +for this approach). This guarantees a "best effort precision".
>>>>  */
>>>> -#define B0 1.00000000000000000000
>>>> -#define B1 0.72095982200694791383 // (cos(pi*1/16)sqrt(2))^-1
>>>> -#define B2 0.76536686473017954350 // (cos(pi*2/16)sqrt(2))^-1
>>>> -#define B3 0.85043009476725644878 // (cos(pi*3/16)sqrt(2))^-1
>>>> -#define B4 1.00000000000000000000 // (cos(pi*4/16)sqrt(2))^-1
>>>> -#define B5 1.27275858057283393842 // (cos(pi*5/16)sqrt(2))^-1
>>>> -#define B6 1.84775906502257351242 // (cos(pi*6/16)sqrt(2))^-1
>>>> -#define B7 3.62450978541155137218 // (cos(pi*7/16)sqrt(2))^-1
>>>> -
>>>> -
>>>> -#define A1 0.70710678118654752438 // cos(pi*4/16)
>>>> +#define B0 1.000000000000000000000000000000000000L
>>>> +#define B1 0.720959822006947913789091890943021267L // (cos(pi*1/16)sqrt(2))^-1
>>>> +#define B2 0.765366864730179543456919968060797734L // (cos(pi*2/16)sqrt(2))^-1
>>>> +#define B3 0.850430094767256448766702844371412325L // (cos(pi*3/16)sqrt(2))^-1
>>>> +#define B4 1.000000000000000000000000000000000000L // (cos(pi*4/16)sqrt(2))^-1
>>>> +#define B5 1.272758580572833938461007018281767032L // (cos(pi*5/16)sqrt(2))^-1
>>>> +#define B6 1.847759065022573512256366378793576574L // (cos(pi*6/16)sqrt(2))^-1
>>>> +#define B7 3.624509785411551372409941227504289587L // (cos(pi*7/16)sqrt(2))^-1
>>>
>>> iam not sure how portable x.yL is
>>> otherwise should be ok
>>
>> Technically C89, see e.g
>> http://port70.net/~nsz/c/c89/c89-draft.html#3.1.3.1, wikipedia, or
>> http://en.cppreference.com/w/cpp/language/floating_literal.
>> Nevertheless, will wait for comments especially from people who use
>> Microsoft stuff.
>
> Is portable, since recent commit by me a5202bc9 for the Bessel
> function from boost has such a literal (line 118, swresample/resample)
> and does not seem to have caused build failures anywhere. Actually,
> there the L was an artifact left over from Boost and I will remove it.
>
> Will push in light of this. Also will push the trivial removal of the
> L leftover in swresample.

pushed both, thanks.

>
>>
>>>
>>> [...]
>>> --
>>> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>>>
>>> Its not that you shouldnt use gotos but rather that you should write
>>> readable code and code with gotos often but not always is less readable
>>>
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>>


More information about the ffmpeg-devel mailing list