Forum Discussion

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

problem: to_ufixed(0.483,n1)

Hi all;

I want to convert 0.483 to ufixed type. Manually, I get 0000.0111 (3 downto -4) when I calculate by hand.

But, this value is not same with the value in modelsim which is 0000.1000. I write like this;

ip1<=to_ufixed(0.483,n1);

What the correct value of 0.483 in ufixed? Do I calculate in wrong way?..needs help, thanks

10 Replies

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

    Its 0000.1000 if you round to nearest.

    the to_ufixed function does have extra options with regards to rounding and saturation. You'll have to read the function definitions in the fixed_pkg source code or user guide to set them.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    0.483 * 2^4 = 7.728, which gets rounded up to 8, which is 1000 in binary. To me it seems Modelsim is right.

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

    Sorry, what actually the formula to convert to ufixed? thanks for reply

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

    I try 1 example (0.25) for my better understand;

    0.25x2^2 = 0.5 which get rounds 1, which is 1 in binary.

    Do I right? thanks for reply
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    I try 1 example (0.25) for my better understand;

    0.25x2^2 = 0.5 which get rounds 1, which is 1 in binary.

    Do I right? thanks for reply

    --- Quote End ---

    No, 0.25 x 2^2 = 1

    Answer is 0.01
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Sorry for the miss typing..and I think I misunderstanding the concept.

    I try another example (9.75):

    9.75x2^2=39 which is 100111 in binary. The answer is 1001.11

    Do I right? thanks for reply