Operators and Math Functions

The expr command recognizes the following operators, in decreasing order of precedence:

+ − ˜ !

Unary plus and minus, bitwise NOT, logical NOT

* / %

Multiply, divide, remainder

+ −

Add, subtract

<< >>

Bitwise shift left, bitwise shift right

< > <= >=

Boolean comparison for less than, greater than, less than or equal, greater than or equal

== !=

Boolean test for equality, inequality

&

Bitwise AND

^

Bitwise exclusive OR

|

Bitwise inclusive OR

&&

Logical AND

||

Logical OR

x?y:z

If x !=0, then y, else z

All operators support integers. All except ˜, %, <<, >>, &, ^, and | support floating-point values. Boolean operators can also be used for string operands, in which case string comparison will be used. This will occur if any of the operands are not valid numbers. The &&, ||, and ?: operators have lazy evaluation, as in C, in which evaluation stops if the outcome can be determined.

The expr command also recognizes the following math functions:

abs(arg)

Absolute value of arg

acos(arg)

Arc cosine of arg

asin(arg)

Arc sine of arg

atan(arg)

Arc tangent of arg

atan2(x, y)

Arc tangent of x/y

ceil(arg)

Rounds arg up to the nearest integer

cos(arg)

Cosine of arg

cosh(arg)

Hyperbolic cosine of arg

double(arg)

Floating-point value of arg

exp(arg)

e to the power of arg

floor(arg)

Round arg down to the nearest integer

fmod(x, y)

Remainder of x/y

hypot(x, y)

sqrt (x*x + y*y)

int(arg)

arg as integer by truncating

log(arg)

Natural logarithm of arg

log10(arg)

Base 10 logarithm of arg

pow(x, y)

x raised to the exponent y

rand()

Random floating-point number ≥ 0 and < 1

round(arg)

arg as integer by rounding

sin(arg)

Sine of arg

sinh(arg)

Hyperbolic sine of arg

sqrt(arg)

Square root of arg

srand(arg)

Seeds random number generator using integer value arg

tan(arg)

Tangent of arg

tanh(arg)

Hyperbolic tangent of arg

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset