[Vorbis-dev] Qyery on bark equation in floor0 code
Tuomo Latto
djv at mbnet.fi
Wed Dec 29 07:17:34 PST 2004
Sebastian Gesemann wrote:
> On Tue, 28 Dec 2004, Monty wrote:
>>>On Friday 17 December 2004 15:25, nagaraja.sreerama at wipro.com wrote:
>>>>(a) In the specification, the bark(x) equation is given as:
>>>>bark(x) = 13.1 atan(.00074x) + 2.24 atan(.0000000158(x^2)) + .0001x
>>>>
>>>>whereas in the code it is given as:
>>>>#define toBARK(n)
>>>>(13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
>>
>>The spec has the digits transposed. The code is correct.
>
> They are not equivalent. See the first formula: the last
> "0.0001x" is *outside* the ATAN().
To be anal about it and just generally irritating:
"1e-4f*(n)" is also outside the atan(). The whole macro is wrapped in parentheses.
BTW, that is always the preferred way so that the preprocessor doesn't
accidentally change the intended order of evaluation in situations like
"x * toBARK(y)". (Try manual substitution with vs. without the parentheses.)
Similarly, when defining function-like macros that have more than one clause,
one should always surround the body of macro with braces ie. define the macro
as a block. This is done to avoid things like "if(x) MACRO(y);" turning
into something catastrophic.
--
Tuomo
... "Bother!" said Pooh, as he felt a disturbance in the Force
More information about the Vorbis-dev
mailing list