Floating Point Values

NI-VISA

Floating Point Values

When writing floating point values to or reading them from the instrument, you can use %f or %e format codes with length modifiers (l and L) and the array modifier (,). Floating point values are important when programming a numeric value transfer.

Note  %f does not fully represent a floating point value in the extreme cases. Use %e for a floating point value in such cases.

Double Float—"%le"

Use this modifier for double (64 bit) floats. These are typically used for data value transfers.

Examples

This example shows how to scan the vertical range (a 64 bit floating point number).

/* Query Vertical Range */
ViReal64 value;
viPrintf (io, ":CH1:SCA?\n");
viScanf (io, "%le", &value);

This example shows how to format a trigger delay of 50.0 (specified as a 64 bit floating point number) into the command string sent to an instrument.

/* Send Trigger Delay */
ViReal64 value = 50.0;
viPrintf (io, ":TRIG:DEL %le;", value);

Precision Specifier—"."

Use the precision specifier to specify the number of precision digits when doing a numeric transfer. This modifier sets the accuracy of the values.

Example

This example shows how to set the voltage resolution. The resolution is represented in a double floating point (64 bits). The precision modifier .9 specifies that there are nine digits after the decimal point. In this case, 0.000000005 is sent to the instrument.

/* Set Resolution */
ViReal64 value = 0.0000000051;
viPrintf (io, "VOLT:RES %.9le", value);

Array of Floating Point Values Specifier—","

Use this modifier when transferring an array of floating point values to or from an instrument. The count of the number of elements can be represented by a constant, asterisk (*) sign, or number (#) sign. The asterisk (*) sign indicates the count is the first argument on viPrintf(). The number (#) sign indicates that the count is the first argument on viScanf(), and the count is passed by address. You can use the constant with both viPrintf() and viScanf().

Examples

This example shows how to send an array of double numbers to the instrument. The comma (,) indicates the parameter is an array and the asterisk (*) specifies the array size to be passed in from the argument.

/* Create User Defined Mask */
ViInt32 maskSize = 100;
ViReal64 interleaved[100];
/* define points in the specified mask and store them in the array */
viPrintf (io, ":MASK:MASK1:POINTS %*,le", maskSize, interleaved);

This example shows how to take multiple readings from an instrument. The comma (,) indicates the parameter is an array and the number (#) sign specifies the actual number of readings returns from the instrument.

/* Read Multi-Point */
ViInt32 readingCnt = 50;
ViReal64 readingArray[50];
viQueryf (io, "READ?\n", "%,#le", &readingCnt, readingArray);

This example shows how to fetch multiple readings from an instrument. The comma (,) indicates the parameter is an array while the constant 1000 specifies the number of readings.

/* Fetch Multi-Point */
ViReal64 readingArray[1000];
viScanf (io, "%,1000le", readingArray);