# [flac-dev] A condition in precompute_partition_info_sums_()

lvqcl lvqcl.mail at gmail.com
Mon May 18 09:47:15 PDT 2015

```The commit http://git.xiph.org/?p=flac.git;a=commitdiff;h=0a0a10f358345f749e4a05021301461994f1ffc5
(from 31 Mar 2007) adds the following conditional:

if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32)

And the commit http://git.xiph.org/?p=flac.git;a=commitdiff;h=f081524c19eeafd08f4db6ee5d52a9634c60f475
has this:

if(FLAC__bitmath_ilog2(default_partition_samples) + bps + FLAC__MAX_EXTRA_RESIDUAL_BPS < 32)

The question is: why ... < 32, not ... <= 32 ?

Basically we want to know the number of bits that is necessary to represent
the value of (default_partition_samples * max_value_of_residual) product.

Let's assume that the bitness of the residual signal is N. The minimum value
is -2^(N-1), the max is 2^(N-1)-1. For the absolute value: max = 2^(N-1).

The number of bits in default_partition_samples is equal to
FLAC__bitmath_ilog2(default_partition_samples) + 1.
When we multiply default_partition_samples with 2^(N-1) we add N-1 zeroes to it,
so the number of bits in (default_partition_samples*max_value_of_residual) is equal to

FLAC__bitmath_ilog2(default_partition_samples) + 1 + N - 1, i.e.
FLAC__bitmath_ilog2(default_partition_samples) + N

The value of (default_partition_samples*max_value_of_residual) should fit
into unsigned 32-bit variable, so the condition should be:

FLAC__bitmath_ilog2(default_partition_samples) + N <= 32
```