From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

fixed point conversion

Solved!
Go to solution

How would like to know how LabVIEW manages type conversion and type cast to fixed point.

In particular I have got two problems:

 

1) Suppose that I want to convert a signed 32-bit integer to a fixed point <+/-,20,20> with the "To-fixed-point" function.

Of course this conversion implies a loss of bits. Will LabVIEW keep the most significant bits or the least significant ones?

The same problem occurs if I want to convert a fixed point data (e.g. <+/-,20,20>) to another fixed point data with less bits (e.g. <+/-,10,10>).

 

2) I have a data represented with a fixed point <+/-,20,10> and I want to cast it to a fixed point <+/-,15,5> by removing 5 integer bits and keeping the sign.

For example I have the number -1.5 represented in <+/-,20,10> and I want to cast it to <+/-,15,5> (note that both representations can express the number correctly).

How can I perform such casting operation?

 

Thank you

0 Kudos
Message 1 of 7
(6,638 Views)

Hi tom,

 

why don't you just try on your own?

check.png

It seems, both use the same bit representation as can be seen when setting both indicators to binary display...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(6,633 Views)

Thank GerdW for answering.

Indeed, I tried some (all?) functions available to perform a cast between integers and fixed-point (FP) numbers.

This would not have been necessary if the LabVIEW documentation was a little more clear on the topic.

 

Anyway, I resume my results just in case anyone is interested.

In the following I assume that no overflow occurs. Moreover, all conversions are lossy: i.e. the final type has less bit than the initial one.

Integer -> FP:

FUNCTION                                     EFFECT                                     EXAMPLE -2 (=11111110b) int8 TO <+/-,6,4>

To Fixed-Point                                 Preserve point position                 1110.00b

Type Cast                                       Preserve MSB                             1111.11b

Integer To Fixed-Point Cast              Preserve LSB                              1111.10b

 

FP -> FP

FUNCTION                                     EFFECT                                     EXAMPLE 0000.1101b <+/-,8,4> TO <+/-,6,3>

To Fixed-Point                                 Preserve point position                 000.110b

Type Cast                                       Preserve MSB                             000.011b

 

FP -> Integer:

FUNCTION                                     EFFECT                                     EXAMPLE 00001.11010b <+/-,10,5> TO int8

To Integer                                       Round to nearest integer               00000010b

Type Cast                                       ???                                             00001110b

Integer To Fixed-Point Cast              Preserve LSB                              00111010b

 

Please tell me if I missed or misunderstood anything.

Message 3 of 7
(6,607 Views)

Hi Tom,

 

What version of LabVIEW are you using?  We put some effort into improving the accuracy of the documentation on the FXP-Integer Cast functions in 2010, so if you are in that version or later, I'd be interested in specific recommendations on what is deficient. For example, are the individual function topics unclear, or is it more that you can't find an overview of all the behaviors?

 

Thanks,


Jim

0 Kudos
Message 4 of 7
(6,595 Views)

I am using LabVIEW 2010.

Currently I am using the FPGA module and the Control Design and Simulation Toolkit.

I know that writing good documentation is hard and I appreciate your efforts.

Nevertheless, I cannot find a detailed description of type cast effects, which is quite important if you are dealing with an FPGA.

0 Kudos
Message 5 of 7
(6,581 Views)
Solution
Accepted by topic author tommpogg

Hi Tom,

 

That's a fair criticism, there's probably some tribal knowledge implicit in the documentation. I'll provide a few background notes that might help a bit:

 

  • LabVIEW makes a distinction between conversion functions (aka "bullets") and casts. Conversion functions always attempt to preserve the numeric value, with out-of-range values handle with various rounding and overflow modes. Integer/integer conversions wrap, while all other combinations round to nearest and saturate by default. If the destination is FXP, you can configure the modes yourself.
  • Coercion dots have the same behaviors as their corresponding conversion function.
  • Type Cast is not supported on the FPGA
  • The Fixed-Point to Integer Cast and Integer to Fixed-Point Cast were created with FPGA use cases in mind. They are not pure bit casts, as they do support sign extension for arithmetic scaling, as well as overflow handling modes. Hopefully the new documentation is somewhat more clear on their behavior.
  • Reinterpret Number is a pure bit cast for FXP or integer numbers, available on the Numeric>>Fixed-Point palette only under FPGA targets. It simplifies the behaviors by restricting the input and output word lengths to be identical.

 

Message 6 of 7
(6,568 Views)

Thank you for your explanation.

 

As a suggestion, I recommend to add some examples to LabVIEW Help, just like I tried to do in my previous post (actually it can be done better than I did).

 

0 Kudos
Message 7 of 7
(6,544 Views)