Use the Comparison functions to compare numeric values, strings, Boolean values, arrays, and clusters. Most Comparison functions test one input or compare two inputs and return a Boolean value.

Most of the Comparison functions test one input or compare two inputs and return a Boolean value. The functions convert numbers to the same representation before comparing them. The functions convert each input to the largest representation needed to make an accurate comparison. Comparisons with one or two inputs that have the value not a number (NaN) return a result that indicates that the comparison was not equal.

Not all real numbers can be represented in the ANSI/IEEE standard floating-point numbers. Because of this, comparisons using floating-point numbers may yield results you do not expect because of rounding errors.

Comparison functions compare strings according to the values of the ASCII characters codes. Comparison functions compare strings one element at a time starting with the 0th element until they encounter an inequality or until one string ends. The functions treat the longer string as greater than the shorter string.

For example, a (with a decimal value of 97) is greater than A (65), which is greater than the numeral 0 (48), which is greater than the space character (32). LabVIEW compares characters one by one from the beginning of the string until an inequality occurs, at which time the comparison ends. For example, LabVIEW evaluates the strings abcd and abef until it finds c, which is less than the value of e. The presence of a character is greater than the absence of one. Thus, the string abcd is greater than abc because the first string is longer.

The functions that test the category of a string character, such as the Decimal Digit? and Printable? functions, evaluate only the first character of the string.

The Comparison functions treat the Boolean value TRUE as greater than the Boolean value FALSE.

Some Comparison functions have two modes for comparing arrays or clusters of data. In Compare Aggregates mode, if you compare two arrays or clusters, the function returns a single Boolean value. In Compare Elements mode, the function compares the elements individually and returns an array or cluster of Boolean values.

In Compare Aggregates mode, the string comparison and array comparison operations follow exactly the same process—the Comparison function treats the string as an array of ASCII characters.

Note The Max & Min function behaves differently than other comparison functions. The Max & Min function returns either the maximum element or array or the minimum element or array, depending on which mode you specify and which output you specify. |

Right-click a Comparison function and select **Comparison Mode»Compare Elements** or **Comparison Mode»Compare Aggregates** from the shortcut menu to change the mode of the function. Some Comparison functions operate only in Compare Aggregates mode, so the shortcut menu items do not appear.

When comparing multidimensional arrays, each array wired to the function must have the same number of dimensions. The Comparison functions that operate only in Compare Aggregates mode compare arrays the same way they compare strings—one element at a time starting with the first element until they encounter an inequality.

In Compare Elements mode, Comparison functions return an array of Boolean values of the same dimensions as the input arrays. Each dimension of the output array is the size of the smaller of the two input arrays in that dimension. Along each dimension such as a row, column, or page, the functions compare corresponding element values in each input array to produce the corresponding Boolean value in the output array.

In Compare Aggregates mode, comparison functions return a single Boolean result after comparing the elements in an array. Comparison functions compare elements sequentially until a decision can be made, much like the alphabetical ordering of English words, where letters of each word are compared until they are not equal. Therefore, the function performs the following steps to determine the result of the comparison:

- The function compares corresponding elements in each input array, starting at the beginning of the array.
- If the corresponding elements are
*not*equal, the function stops—it returns the result of this comparison. - If the corresponding elements are equal, the Comparison function processes the next pair of values, until it finds an inequality or reaches the end of one of the input arrays.
- If all values in the input arrays are equal but one array has extra elements at the end, the longer array is considered greater than the shorter one. For example, a Comparison function considers the array [1,2,3,2] to be greater than the array [1,2,3].

Note The In Range and Coerce function behaves differently than other Comparison functions in Compare Aggregates mode because it requires three inputs. After comparing the first set of elements, the function processes the next set of values only if all three inputs, upper limit, lower limit, and x, are equal. Otherwise, the function returns the result of comparing the first set of elements. |

Clusters you compare must include the same number of elements, each element in the clusters must be of compatible types, and the elements must be in the same cluster order. For example, you can compare a cluster of a DBL and a string to a cluster of an I32 and a string.

In Compare Elements mode, Comparison functions return a cluster of Boolean elements, one for each corresponding element in the input clusters.

In Compare Aggregates mode, comparison functions return a single Boolean result after comparing the elements in a cluster. Comparison functions compare elements sequentially until a decision can be made, much like the alphabetical ordering of English words, where letters of each word are compared until they are not equal. Therefore, the function performs the following steps to determine the result of the comparison:

- The function compares corresponding elements in each input cluster, starting at the beginning of the cluster.
- If the corresponding elements are
*not*equal, the function stops—it returns the result of this comparison. - If the corresponding elements are equal, the comparison function processes the next pair of values, until it finds an inequality or reaches the end of the input clusters.
- If all values in the input clusters are equal but one cluster has extra elements at the end, the larger cluster is considered greater than the smaller one. For example, a Comparison function considers the cluster [1,2,3,2] to be greater than the cluster [1,2,3].

Note The In Range and Coerce function behaves differently than other Comparison functions in Compare Aggregates mode because it requires three inputs. After comparing the first set of elements, the function processes the next set of values only if all three inputs, upper limit, lower limit, and x, are equal. Otherwise, the function returns the result of comparing the first set of elements. |

Use Compare Aggregates mode on clusters if you are comparing two records containing sorted data, where elements later in the cluster are considered secondary to elements earlier in the cluster. For example, if you compare a cluster containing two strings, last name followed by first name, the function would compare the first name fields only if the last name fields matched.

LabVIEW compares VI Server references using the Equal? and Not Equal? comparison functions. You can use these comparison functions to compare an array or cluster of a data type to a scalar of the same data type and produce an array or cluster of Boolean values. When comparing VI Server references, these functions return TRUE or FALSE based on whether the two references refer to the same object, regardless of whether the references have the same value or the same capability. Because you can have multiple references to the same object, the integer value of the references can be different but still refer to the same object. The capability of two references also can differ even though they both might refer to the same object. For example, if one of the references is authenticated while the other is not, the references would have different capabilities but could still refer to the same object.

For example, one VI Server reference might be a strict reference to a digital numeric control and the other might be a generic reference, but if they refer to the same object, they are equal. Similarly, when two references refer to the same object but one of the references is authenticated and the other is not, the function returns TRUE. However, if you have a local reference and a remote reference to the same LabVIEW object, the Equal? function returns FALSE.

When comparing variant data, the data type, value, attribute name(s), and attribute value(s) must match to be considered equal.