Computational Physics - Department of Physics

(Axel Boer) #1

2.5 Additional Features of C++ and Fortran 33


Table 2.5 lists several relational and arithmetic operators. Logical operators in C++ and


arithmetic operators relation operators
operator effect operator effect
− Subtraction > Greater than



  • Addition >= Greater or equal
    ∗ Multiplication < Less than
    / Division <= Less or equal
    %or MOD Modulus division == Equal
    −− Decrement != Not equal
    ++ Increment
    Table 2.5Relational and arithmetic operators. The relation operators act between two operands. Note that
    the increment and decrement operators++and−−are not available in Fortran.


Fortran are listed in 2.6. while Table 2.7 shows bitwise operations.


Logical operators
C++ Effect Fortran
0 False value .FALSE.
1 True value .TRUE.
!x Logical negation .NOT.x
x&& y Logical AND x.AND.y
x||y Logical inclusive OR x.OR.y
Table 2.6List of logical operators in C++ and Fortran.


Bitwise operations
C++ Effect Fortran
~i Bitwise complement NOT(j)
i&jBitwise and IAND(i,j)
i^jBitwise exclusive or IEOR(i,j)
i|jBitwise inclusive or IOR(i,j)
i<<jBitwise shift left ISHFT(i,j)
i>>nBitwise shift right ISHFT(i,-j)
Table 2.7List of bitwise operations.


C++ offers also interesting possibilities for combined operators. These are collected in
Table 2.8.


Expression meaning expression meaning
a += b; a = a + b; a -= b; a = a - b;
a*= b; a = a*b; a /= b; a = a / b;
a %= b; a = a % b; a «= b; a = a « b;
a »= b; a = a » b; a &= b; a = a & b;
a |= b; a = a | b; a∧= b; a = a∧b;

Table 2.8C++ specific expressions.


Finally, we show some special operators pertinent to C++ only. The first one is the?oper-
ator. Its action can be described through the following example

Free download pdf