Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
16597 Discussions

What is the best Floating number method?

Altera_Forum
Honored Contributor II
1,294 Views

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...:)
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
258 Views

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

0 Kudos
Altera_Forum
Honored Contributor II
258 Views

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

0 Kudos
Altera_Forum
Honored Contributor II
258 Views

 

--- 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
0 Kudos
Altera_Forum
Honored Contributor II
258 Views

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

0 Kudos
Reply