Compound Arithmetic


While we're on the subject of arithmetic, we should mention the Compound Arithmetic function (see Figure 7.38). While the previous polymorphism example showed you how to add and multiply different-sized data together, this function lets you operate on more than two numbers simultaneously. The Compound Arithmetic function eliminates the need for multiple Add, Multiply, AND, OR, and XOR terminals should you need to perform one of these functions on several numbers at once (AND, OR, and XOR are Boolean arithmetic operations).

Figure 7.38. (Left) Compound Add Function (Right) Compound And Function


The Compound Arithmetic function can be found in both the Numeric and Boolean subpalettes of the Functions palette. Like many other functions, you can use the Positioning tool to grow it and provide more input terminals. The Compound Arithmetic function has only one form; you configure it to perform the arithmetic function of your choice. To change the function (choices are Add, Multiply, AND, OR, or XOR), pop up on the output terminal and select Change Modes. You can also click on the function with the Operating tool to change the mode.

Select the Invert pop-up option to invert the sign of numeric inputs and outputs or the value of Booleans (from FALSE to TRUE or vice versa), as shown in Figure 7.39. A small circle at the input or output symbolizes an inverted value.

Figure 7.39. Selecting the Invert option from the pop-up menu of one of the terminals of the Compound Arithmetic function.


The Invert option has a different effect depending on the Compound Arithmetic function's mode of operation (as selected from the Change Mode pop-up submenu). Table 7.1 shows the effect of the invert option, applied to an input, for each of the Compound Arithmetic function's modes of operation.

Table 7.1. The Effect of an Inverted Input for Each Compound Arithmetic Mode

Mode

Non-Inverted Input

Inverted Input

Add

add input

add (0input)

Multiply

multiply input

multiply (1/input)

AND

AND input

AND (NOT input)

OR

OR input

OR (NOT input)

XOR

XOR input

XOR (NOT input)


When the Invert option is applied to an output, the function is similar. Table 7.2 shows the effect of the invert option, applied to an output, for each of the Compound Arithmetic function's modes of operation.

Table 7.2. The Effect of an Inverted Output for Each Compound Arithmetic Mode

Mode

Non-Inverted Output

Inverted Output

Add

result

0result

Multiply

result

1/result

AND

result

NOT result (NAND)

OR

result

NOT result (NOR)

XOR

result

NOT result (NOT XOR)


In order to make this as clear as possible, we have created a collection of equivalent operations, shown in Figure 7.40. This is meant only to help you see the underlying principles. (Don't worry; this won't be on the quiz.)

Figure 7.40. Equivalent standard and compound arithmetic operations (in columns)


For a simpler example of some practical ways to use the compound arithmetic node, see Figure 7.41. The two equivalent operations on the left show how you can use the compound arithmetic node for combined addition and subtraction. The two equivalent operations on the right show how you can use the compound arithmetic node for combined multiplication and division.

Figure 7.41. Equivalent standard and compound arithmetic operations (in columns)


A Word About Boolean Arithmetic

LabVIEW's Boolean arithmetic functionsAnd, Or, Not, Exclusive Or, Not Exclusive Or, Not And, and Not Orcan be very powerful. You will see occasional Boolean arithmetic throughout this book. If you've never seen it before, we recommend reading about it in a good logic or digital design book. But just as a refresher, we'll mention a few basics. If you can't remember which function does what, use the Help window!

Not is probably the easiest to describe, because it simply inverts the input value. If the input value is TRUE, Not will output FALSE; if the input is FALSE, Not returns TRUE.

The And function outputs a TRUE only if all inputs are TRUE.

The Or function outputs a TRUE if at least one input is TRUE.

The And and Or functions have the following outputs, given the inputs shown:

FALSE And FALSE = FALSE

TRUE And FALSE = FALSE

FALSE And TRUE = FALSE

TRUE And TRUE = TRUE

FALSE Or FALSE = FALSE

TRUE Or FALSE = TRUE

FALSE Or TRUE = TRUE

TRUE Or TRUE = TRUE




LabVIEW for Everyone. Graphical Programming Made Easy and Fun
LabVIEW for Everyone: Graphical Programming Made Easy and Fun (3rd Edition)
ISBN: 0131856723
EAN: 2147483647
Year: 2006
Pages: 294

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net