Hide minor edits - Show changes to markup
These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type. If the operands are of different types, the "larger" type is used for the calculation.
These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type (e.g. adding 1 to an int with the value 32,767 gives -32,768). If the operands are of different types, the "larger" type is used for the calculation.
If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the operation.
If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the calculation.
These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type. If the operands are of different types, the "larger" type is used for the calculation.
These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type. If the operands are of different types, the "larger" type is used for the calculation.
If one of the numbers (operands) are of the type float or of type double, floating point math will be used for the operation.
The arithmetic operators work exactly as one expects with the result returned being the result of the two values and the operator
These operators return the sum, difference, product, or quotient (respectively) of the two operands. The operation is conducted using the data type of the operands, so, for example, 9 / 4 gives 2 since 9 and 4 are ints. This also means that the operation can overflow if the result is larger than that which can be stored in the data type. If the operands are of different types, the "larger" type is used for the calculation.
result = value1 [+-*/] value2
result = value1 + value2; result = value1 - value2; result = value1 * value2; result = value1 / value2;
value1: any variable type
value2: any variable type
value1: any variable or constant
value2: any variable or constant
A longer tutorial on computer math can eventually go in this space but for now, to benefit beginning programmers some general guidelines will be presented. These will hopefully get you started toward getting the same answer out of your Arduino that you do on your calculator.
value1: any variable type
value1: any variable type\\\
For beginning programmers there are several details of doing math on the computer to which one must pay attention. One is that math on computers, as opposed to algebra class, must exist in physical space. This means that the variable (which occupies a physical space on your Atmega chip) must be large enough to hold the results of your calculations.
Hence if you try something like this
byte x; x = 255; x = x + 1;
A longer tutorial on computer math can eventually go in this space but for now, to benefit beginning programmers some general guidelines will be presented. These will hopefully get you started toward getting the same answer out of your Arduino that you do on your calculator.
result = value1 [+-*/] value2
[@
@]
x = x + 1;
x = x + 1; @]
The arithmetic operators work exactly as one expects with the result returned being the result of the two values and the operator
y = y + 3; x = x - 7; i = j * 6; r = r / 5;
value1: any variable type value2: any variable type
For beginning programmers there are several details of doing math on the computer to which one must pay attention. One is that math on computers, as opposed to algebra class, must exist in physical space. This means that the variable (which occupies a physical space on your Atmega chip) must be large enough to hold the results of your calculations.
Hence if you try something like this [@ byte x; x = 255; x = x + 1;