Forum Discussion

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

Floating point division

Hi,

does anyone has a code for floating point division?

i tried using the megafunction tool for division but it keeps giving me error when i run simulation.

9 Replies

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

    Floating point division in firmware is no trivial task. You could always offload that problem to a NIOS, but that seems like overkill. Are you sure you can't get by with fixed point or avoiding division entirely?

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

    You could try using integers.

    Multiply the FP numbers by a scalar to convert it to a integer, divide the integers, then convert back to FP or divide down to get just the integer result of the multiplication.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    You could try using integers.

    Multiply the FP numbers by a scalar to convert it to a integer, divide the integers, then convert back to FP or divide down to get just the integer result of the multiplication.

    --- Quote End ---

    Floating to integer conversion is not as simple as "multiply by a scaler", you need to do a full conversion. You may be thinking of fixed point, which is just integer arithmatic anyway.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    FP division is probably simpler than integer division - especially if you aren't worried about underflow, overflow, infinities, NaNs and denormalised small values.

    Extract and subtract the exponents and then divide the mantissa's - which both start with a 1.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    For a 32 bit floating point number, i would like to know the split of signbit,exponent,mantissa.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The format is explained in the FP MegaFunction user manual. Or google for IEEE 754.

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

    Sign bit : Exponent (8 bits) : Mantissa (23 bits)

    Keep in mind that the mantissa has the implied '1' that DSL referred to which isn't stored as part of the manatissa field.

    Back when I was working on floating point stuff I found this webpage very handy: http://www.h-schmidt.net/floatconverter/ieee754.html

    So DSL said to subtract bits [30:23] and divide bits {1'b1, [22:0]}. For the sign bit you could just XOR those bits since both positive or both negative should result in a positive result (sign bit = 0).
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You are then dividing two values between 0.5 and 1.999999999 - so the exponent may need changing by 1 (or 2?) in order to normalise the resultant mantissa.

    You should also worry aout the rounding rules (round to even is normally specified by default).