Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

What is the best Floating number method?

Hello friends...

I want to know what is the efficient code to implement this equation :

1/4 ( x+y) + 1/2

However, inputs are integers , and the output will be also rounded to integer. But the intermediate calculations needs to use 1/4 and 1/2.

Kindly inform me about the best way to code this equation.

Thanks...:)

4 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    use fixed point. Its just integer with an offset (so easily implemented in an FPGA).

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    PS: (x+y)/4 + 1/2 is identical to the equation (x+y + 2) /4. divides by 2^n are just a bit shift.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    use fixed point. Its just integer with an offset (so easily implemented in an FPGA).

    --- Quote End ---

    yes use fixe point. just add x + y then add half of result and truncate 2 LSBs

    I am assuming you want to add x+y, divide by 4 then round
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you very much. I am coding it right now to see how it is going. Best regards.