FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6355 Discussions

## Floating Point result to the decimal one

Honored Contributor II
1,402 Views

I would like to convert the Mantissa Result to the Decimal one with floating point included.

The steps I do:

1). I'm interested to divide two decimal numbers . For example 10 and 3 ===> 10/3

2). Using the Mega Wizard Core for conversion the decimal numbers to mantissa (ALTFP_CONVERT).

3). Dividing the mantissa result of 10 on the mantissa result of 3 by Mega Wizard Core (ALTFP_DIV).

4). The dividing result still presented in the mantissa form.

5). At the end i'd like to convert it back to the decimal form with floating point (to get 10/3 = 3.3). But the IP Core converting the result only into the decimal 3 and not into 3.3. The mantissa part was neglected, only the exponent part is taking the place.

Am I making a mistake during the conversion steps?

thanks
5 Replies
Honored Contributor II
342 Views

I don't know what you mean with "mantissa format". An IEEE float number is comprised of mantissa and exponent.

There's however no conversion to a fixed point decimal format provided. If you want to see something like 3.3, you need to multiply the float result with 10 (or 100, 1000, whatsoever) and convert back to integer. You get a result of 33, 333 or 3333 in your example, which can be interpreted as fixed point decimal format.
Honored Contributor II
342 Views

That's exactly what I mean - mantissa format is the IEEE float number.

There is no other way to present the number 3.3? Only the multiplying?

Thanksss
Honored Contributor II
342 Views

That's what e.g. a printf("%f", ) routine is supposed to do.

Honored Contributor II
342 Views

If you want one digit to the right of the decimal point, then multiply the dividend by 10 prior to the division, then insert a decimal point before the last digit in teh output (or whatever).

ie use 'fixed point arithmentic'.

Of course, depending on what you are doing, it might make more sense to multply by some power of 2.
Honored Contributor II
342 Views

Not that I have any clue why you are doing this but this might be easier:

1) 10/3 --> 3 and remainder 1 (use lpm_div)

2) 1(remainder from# 1)/3-->0.333333 (using altfp_convert followed by altfp_div)

3) 0.333333 * 10 (using altfp_mul)

4) 3.333333 convert to 3 to get the remainder with one decimal place (using altfp_convert to bring it back to a whole number)

So step 1 gets you the digits to the left of the decimal place and steps 2-4 get you the first digit after the decimal place. That said this is a lot of hardware that I would normally just have a CPU calculate for me using software libraries.