Announcement

Collapse
No announcement yet.

Arithmetic Operators

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Arithmetic Operators

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - Arithmetic Operators
    Arithmetic operators perform normal mathematical operations. Several of these operators merit a word of explanation. The backslash (&#92 represents integral division. Integral division rounds its operands to an integral value, to produce a truncated quotient with no remainder. For example, 5 \ 2 evaluates to 2, and 9 \ 10 evaluates to 0. Integral division is also faster than floating-point division when using integral-class variables or expressions.

    The remainder of an integral division can be determined with the MOD (modulo) operator (MOD is valid for all numeric types). MOD is similar to integer division except that it returns the remainder of the division rather than the quotient. For example, 5 MOD 2 returns the value 1, and 9 MOD 10 returns the value 9.

    The ISTRUE operator returns TRUE only if its operand is TRUE (non-zero). ISTRUE is guaranteed to return -1 as its TRUE value, whereas the operators can return any non-zero value.

    The ISFALSE operator returns TRUE only if its operand is FALSE (zero). ISFALSE is guaranteed to return -1 as its TRUE value, where the operators can return any non-zero value.

    PowerBASIC arithmetic operators
    Code:
    +---------------------------------------------------------------------------------------------------------------------------+
    | Operator                      | Action                      | Example                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | ^                             | Exponentiation              | 10^4                                                        |
    +---------------------------------------------------------------------------------------------------------------------------+
    | -                             | Negation                    | -16                                                         |
    +---------------------------------------------------------------------------------------------------------------------------+
    | *                             | Multiplication              | 45 * 19                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | /                             | Floating-point division     | 45 / 19                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | \                             | Integral division           | 45 \ 19                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | +                             | Add                         | 45 + 19                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | -                             | Subtract                    | 45 - 19                                                     |
    +---------------------------------------------------------------------------------------------------------------------------+
    | MOD                           | Modulo                      | 45 MOD 19                                                   |
    +---------------------------------------------------------------------------------------------------------------------------+
    | ISFALSE                       | Boolean False               | ISFALSE 45                                                  |
    +---------------------------------------------------------------------------------------------------------------------------+
    | ISTRUE                        | Boolean True                | ISTRUE 19                                                   |
    +---------------------------------------------------------------------------------------------------------------------------+
    | NOT, AND,  OR, XOR,  EQV, IMP | Bit manipulation operations | NOT 0, 45 AND 19, 45 OR 19, 45 XOR 19, 45 EQV 19, 45 IMP 19 |
    +---------------------------------------------------------------------------------------------------------------------------+
    Note: PowerBASIC does not trap numeric overflow or underflow errors in equation and expression evaluation. Please refer to the topics Errors and Error Trapping for more information.

    It is recommended that this table be read in conjunction with the Mathematical Order of Operator Precedence table, and the effects that operator precedence has on the evaluation of numeric expressions.
    See Also
    Last edited by Gary Beene; 28 Oct 2014, 06:41 PM.

  • #2
    The first paragraph should be
    Arithmetic operators perform normal mathematical operations. Several of these operators merit a word of explanation. The backslash (\) represents integral division. Integral division rounds its operands to an integral value, to produce a truncated quotient with no remainder. For example, 5 \ 2 evaluates to 2, and 9 \ 10 evaluates to 0. Integral division is also faster than floating-point division when using integral-class variables or expressions.
    Rod
    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

    Comment

    Working...
    X