0
\$\begingroup\$

I am trying to write an HDL code for converting floating point numbers in IEEE-754 format to integers and vice-versa. For eg.

    for floatToInt operation:
    input = 8.9 (in IEEE-754 format)
    output = 9  (an integer number)

    for intToFloat operation:
    input = 10 (an integer number)
    output = 10.00 (in IEEE-754 format)

In my code, I also need to take care of all the exceptions that might be generated while doing this. Please explain or point me to a good article which exhaustively explains the general procedure/algorithm to do so. I would be very obliged. Thanks in advance.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Google a paper called "What every computer scientist should know about floating point arithmetic". This should give you enough background to answer your own question. \$\endgroup\$
    – The Photon
    Sep 21, 2015 at 8:07
  • \$\begingroup\$ Use the VHDL-2008 fixed and floating point libraries, which are designed to be synthesisable. There are versions for earlier VHDL dialects, see vhdl.org/fphdl \$\endgroup\$
    – user16324
    Sep 21, 2015 at 10:14

1 Answer 1

1
\$\begingroup\$

How about just casting them:

entity x is
end entity x;
architecture STR of x is
    signal i: integer;
    signal r: real;
begin
    i <= integer(r);
    r <= real(i);
end architecture STR;
\$\endgroup\$
1
  • \$\begingroup\$ I am designing a Floating Point Unit and hence must write the codes explicitly \$\endgroup\$
    – titan
    Sep 21, 2015 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.