LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic maths question

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

0 Kudos
Message 1 of 8
(4,368 Views)
I dunno if this helps, but if I drop a numeric constant on the block diagram and change its representation to FXP. Then I type 2.8, it automatically updates to 2.8125. This kind of makes me feel, that the behaviour is happening due to the settings of FXP.
0 Kudos
Message 2 of 8
(4,324 Views)

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)?

 

Message 3 of 8
(4,317 Views)

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

Message 4 of 8
(4,286 Views)

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.

 

 

Message Edited by dan_u on 08-28-2009 04:19 PM
Message 5 of 8
(4,272 Views)

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

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 6 of 8
(4,243 Views)

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


Philip
Applications Engineer
National Instruments
UK Branch

===If this fixes your problem, mark as solution!===
Message 7 of 8
(4,162 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 8 of 8
(4,112 Views)