Forum: FPGA, VHDL & Verilog Round to nearest

Author: Da Ts (danielts)
Posted on:

Rate this post
0 useful
not useful
Hi all,

What are the ways of implementation of "round to nearest" function.
It is an analogue of matlab "round" function. For example:

-2.5 is rounded to -3
2.5 is rounded to 3

Thanks in advance,

Author: Lothar Miller (lkmiller) (Moderator)
Posted on:

Rate this post
0 useful
not useful
Three steps:
1. memorize sign (positive or negative value)
2. round the absolute (positive) value (if >=0.5 then round up)
3. apply sign from step 1 to result


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.