z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Arithmetic functions

z/OS UNIX System Services User's Guide
SA23-2279-00

awk recognizes the most common mathematical functions, as shown in the following table.

Function Result
sqrt(x) Square root of x
sin(x) Sine of x, where x is in radians
cos(x) Cosine of x, where x is in radians
atan2(y,x) Arctangent of y/x in range -pi to pi
log(x) Natural logarithm of x
exp(x) The constant e to the power x
int(x) Integer part of x
rand() Random number between 0 and 1
srand(x) Sets x as seed for rand()

Several of these functions may require more explanation.

The int function takes a floating-point number as an argument and returns an integer. The integer is just the floating-point number, without its fractional part.

Every call to rand returns a new random number between 0 and 1. In this way, you can get a sequence of random numbers. You can use srand to set the starting point, or seed, for a random number sequence. If you set the seed to a particular value, you always get the same sequence of numbers from rand. This is useful if you want a program to use rand but obtain uniform results every time the program runs.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014