Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Numeric Conversion

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

If you wire an output to a destination that has a different numeric representation, LabVIEW converts the data according to the following rules:

  • Signed or unsigned integer to floating-point number—LabVIEW converts the data to the nearest value possible. This conversion is exact when the floating-point number is more precise than the integer. If the integer is more precise than the floating-point number, LabVIEW maintains as much precision as possible in the conversion.
  • Floating-point number to signed or unsigned integer—LabVIEW coerces out-of-range values to the minimum or maximum value of the integer. For example, if you convert a negative floating-point number to an unsigned integer, the result is 0.
  • LabVIEW treats enums as unsigned integers—For example, if you convert –1, a floating-point number, to an unsigned integer, LabVIEW coerces the value into the range of the enum. If the range of the enum is 0 to 25, and you convert –1 to an enum, LabVIEW converts the value to 25, which is the largest value in the range of the enum.
  • Integer to integer—LabVIEW does not coerce out-of-range values to the minimum or maximum value of an integer. If the source is smaller than the destination, LabVIEW extends the sign of a signed source and places zeros in the extra bits of an unsigned source. If the source is larger than the destination, LabVIEW copies only the least significant bits of the value.
  • Integer, floating-point, or fixed-point number to fixed-point number—LabVIEW coerces values outside the desired range for the fixed-point number to within the fixed-point number's maximum and minimum values.

If you wire two different numeric data types to a numeric function that expects the inputs to be the same data type, LabVIEW converts one of the terminals to the same representation as the other terminal. LabVIEW chooses the representation that uses more bits. If the number of bits is the same, LabVIEW chooses unsigned over signed.

Coercion dots appear on block diagram nodes to alert you that you wired two different numeric data types together. The dot means that LabVIEW converted the value passed into the node to a different representation. Coercion dots also appear when LabVIEW discards bits of a fixed-point number. Coercion dots can cause a VI to use more memory and increase its run time. Try to keep data types consistent in the VIs you create.

Tip   To use memory more efficiently, eliminate coercion dots at numeric terminals. <Control>-click the input value on the block diagram and select Representation from the shortcut menu to change the representation of the input value to the representation of the terminal.

Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit