Commit 9fbfa161 authored by multrus's avatar multrus
Browse files

alternative workaround using a multiplication instead of a division

parent b9111040
Loading
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -387,15 +387,12 @@ void ivas_get_dirac_sba_max_md_bits(

#ifdef FIX_FLOAT_1544_SBA_META_IMPRECISION_UNSAFE_MATH
    /*
       The expression ceilf( (float) *metadata_max_bits * nbands / 5 ) was converted to double precision because of issues with -funsafe-math-optimizations,
       where an imprecision of the division in combination with the ceilf()-operator could actually produce different results (+1) for *metadata_max_bits.
       Alternative ways to address this:
       1) Pick up the corresponding code from the BASOP codebase
       2) An expression which takes care of small imprecisions of the division, e.g., ceilf( ( (float) *metadata_max_bits * nbands / 5 ) - 0.1f )
          (minimum non-zero fractional part for X / 5 is 0.2 - substract half of this, to compensate for imprecisions; the ceilf() should still return the correct integer)
       For reasons of code-readability, the variant with double precision was chosen.
      original formula was:
      *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) *metadata_max_bits * nbands / 5 ) );
      The division by 5 is replaced by a multiplication by 0.2f, since the division is causing problems for
      certain optimizations using -funsafe-math-optimizations
    */
    *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) ( (double) *metadata_max_bits * nbands / 5 ) ) );
    *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( *metadata_max_bits * nbands * 0.2f ) );
#else
    *metadata_max_bits = (int16_t) min( (float) MAX16B, ceilf( (float) *metadata_max_bits * nbands / 5 ) );
#endif