Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- FPGAs and Programmable Solutions
- FPGA Intellectual Property
- Floating Point result to the decimal one

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-12-2012
01:42 PM

1,119 Views

Floating Point result to the decimal one

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? thanksLink Copied

5 Replies

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-12-2012
05:03 PM

59 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.
Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-13-2012
05:16 AM

59 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
Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-13-2012
06:46 AM

59 Views

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

Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-13-2012
09:48 AM

59 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.
Altera_Forum

Honored Contributor I

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-13-2012
08:40 PM

59 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.Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.