08-28-2009 03:58 AM
If using the numeric type FXP when you mutiply then divide by 10 you get some strange results if the number is anything other than an basic whole number, for example as shown in the attachment 2,8 offers an answer of 2,8125.
We are trying to create code to run on FPGA and need to round actual data to a single decimal point, anything after the first decimal place is to be discarded - Mike
08-28-2009 08:19 AM
08-28-2009 08:24 AM
The coercion dot at your indicator shows that the representation of the indicator doesn't match the representation of the wire. Are you sure the indicator uses the correct FXP configuration (encoding)?
08-28-2009 09:04 AM
You will not be able to get 2.8 using fixed point. Fixed point numbers are of the type a/b where a is an integer and b is of the type 2^n where n is a positive integer greater than zero. Also, fixed point numbers are configured to have the same number of digits with the binary point at the same location.
When you convert 2.8 to fixed point you get 2.8125 wich is equal to 45/(2^4) the closest value to 2.8. If you try to multiply 2.8 by powers of 2 you will never get an integer value (there is a repeating pattern of 6, 2, 4, 8 digits at the decimal position).
There are a lot of available tutorial on fixed-point arithmetic on the web that can help you, I think that would be a good starting point.
Regards,
Ben
08-28-2009 09:16 AM - edited 08-28-2009 09:19 AM
I agree 2.8 cannot be represented exactly in FXP (this is also true for DBL representation btw), but you can get really close by adjusting the encoding. So with "proper" encoding the result of the calculation shown in the initial post should be closer to 2.8.
But of course, choosing the "proper" encoding is the big challenge when working with FXP numbers.
08-28-2009 12:49 PM
Hi, I'm pretty new to FPGA programming. Is there any reason the values need to be FXP?
Thanks, sorry to hijack the thread, but maybe it's an artificial constraint.
Bill
09-02-2009
03:27 AM
- last edited on
05-20-2025
05:30 PM
by
Content Cleaner
Hello Billko,
Here is a useful Knowladge Base that discusses in detail FXP's. The 5th link LabVIEW Fixed-Point Help explains fully that when using FXP the fixed-point number has a fixed number of integer and fractional bits. Which means hardware and targets that can only store and process data with a limited or fixed number of bits then can store and process the numbers.
I hope this helps
Philip
09-02-2009
09:26 AM
- last edited on
05-20-2025
05:31 PM
by
Content Cleaner
Philip.k wrote:
Hello Billko,
Here is a useful Knowladge Base that discusses in detail FXP's. The 5th link LabVIEW Fixed-Point Help explains fully that when using FXP the fixed-point number has a fixed number of integer and fractional bits. Which means hardware and targets that can only store and process data with a limited or fixed number of bits then can store and process the numbers.
I hope this helps
Philip
That's some pretty cool info. Thanks! (Kudos, too.)
I love this forum because it's all about everyone helping each other out, without (most of the) political faction type of BS that goes on in non-NI help forums.