UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Scholar jprice
Scholar
3,976 Views
Registered: ‎01-28-2014

Fixed Point and Division

Jump to solution

I was looking over the HLS user guide to determine what the results of division were for fixed point types. The guide states:

 

For result = Val2 / Val1:

    This shows the division of Val1 and Val2. To preserve enough precision:
            • The integer bit-width of the result type is sum of the integer = bit-width of Val1 and the fraction bit-width of Val2.
            • The fraction bit-width of the result type is sum of the fraction bit-width of Val1 and thewhole bit-width of Val2.

 

So I try the following code below in a C testbench:

 

   ap_fixed<29,13> t2 = 9.94989;
   cout << t2 << endl;
   cout << ap_ufixed<2,1>(1.0) / t2 << endl;

t2 outputs 9.94987 as expected. The result however is truncated to 0 which does not make sense from the above description. If I give me numerator more fractional bits then my expected result begins to materialize. I feel like either HLS or the documentation is in error and I'm not sure which. Can anyone shed some light on what I'm observing? I'm able to work around it for my design but this is unexpected behavior and I'd like to understand it more.

 

Note that the excerpt is taken from the 2016.2 user guide and the C simulation is run in 2016.2.

 

 

 

0 Kudos
1 Solution

Accepted Solutions
Scholar u4223374
Scholar
7,317 Views
Registered: ‎04-26-2015

Re: Fixed Point and Division

Jump to solution

Looks like an error in UG902. If you have a look on page 668 and 669, you'll find the following statement (with regards to the C++ fixed-point types):

 

For  ap_[u]fixed  types, the fraction is no greater than that of the dividend.

Which is exactly what you're seeing.

0 Kudos
2 Replies
Scholar u4223374
Scholar
7,318 Views
Registered: ‎04-26-2015

Re: Fixed Point and Division

Jump to solution

Looks like an error in UG902. If you have a look on page 668 and 669, you'll find the following statement (with regards to the C++ fixed-point types):

 

For  ap_[u]fixed  types, the fraction is no greater than that of the dividend.

Which is exactly what you're seeing.

0 Kudos
Scholar jprice
Scholar
3,957 Views
Registered: ‎01-28-2014

Re: Fixed Point and Division

Jump to solution

Thanks! I missed that. That makes sense, hopefully they'll catch that and update it.

0 Kudos