Arithmetic Operators

 <  Day Day Up  >  

The arithmetic operators are listed in Table 5-2. They are straightforward, with a few exceptions.

  • The floating-point division operator ( / ) is always performed using floating-point values and always results in a floating-point value. The integer division operator ( \ ), on the other hand, is always performed using integer values and always results in an integer value. Floating-point division is useful when the fractional part of a division operation is significant; integer division is useful when it is not.

    Compatibility

    Unlike in previous versions, dividing by zero with the floating-point division operator will produce the value NaN (Not a Number) instead of a division-by-zero exception. (Handling exceptions is covered in Chapter 7, Exceptions.)


  • The integer remainder operator ( Mod ) calculates the integer remainder when the first operand is evenly divided by the second operand. In other words, x Mod y is equivalent to x “ ((x \ y) * y) .

    Table 5-2. Arithmetic Operators

    Class

    Description

    +

    Addition

    -

    Subtraction and negation

    *

    Multiplication

    /

    Floating-point division

    \

    Integer division

    Mod

    Integer remainder

    ^

    Exponentiation

  • The exponentiation operator ( ^ ) calculates the value of the first operand raised to the power of the second operand.

The arithmetic operators are defined for all the numeric types and Boolean . The result type of an arithmetic operation depends on the type of the operands; in general, the result type of an operation between two different numeric types is the wider of the two types, since this type is most likely to be able to hold the result of the operation.

 <  Day Day Up  >  


The Visual Basic .NET Programming Language
The Visual Basic .NET Programming Language
ISBN: 0321169514
EAN: 2147483647
Year: 2004
Pages: 173
Authors: Paul Vick

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