bcm-v4

[Specification

u32 LP PHY Qdiv Roundup (u32 dividend, u32 divisor, u8 precision)

  1. If divisor == 0
    1. Return 0
  2. Otherwise
    1. Set quotient to dividend / divisor
    2. Set remainder to dividend % divisor
  3. Set (u32) rbit to the bitwise AND of divisor with 1
  4. Set (u32) roundup to divisor right shifted by 1 plus rbit
  5. While precision != 0
    1. Left shift quotient by 1
    2. If remainder >= roundup

      1. increase quotient by 1
      2. Set remainder to (remainder - roundup) left shifted by 1 plus rbit
    3. Otherwise
      1. Left shift remainder by 1
    4. Decrease precision by 1
  6. If remainder >= roundup

    1. Increase quotient by 1
  7. return quotient

(this is really an integer version of round(((double)dividend / (double)divisor) * (double)(1 << precision)))


Exported/Archived from the wiki to HTML on 2016-10-27