High-level Programming Language (Pascal)
Mathematical Functions
- predefined functions that are used to perform arithmetic operation in Pascal
- common characteristic of Pascal function
- has a function name and an argument list
- the function will return a value
- for example, the function sqrt (X) is used to find the square root of the expression or variable inside the bracket
- function has a name (e.g. sqrt), which is followed by expression(s) or variable(s) inside a pair of brackets (e.g. sqrt (X)).
- the returned value of the function sqrt (X) is always a real number.
- the argument X of the function sqrt (X) may be either an integer or a real number which must be greater than or equal to zero
- a list of some common Pascal arithmetic functions is shown as follows:
|
Pascal Function
|
Purpose
|
Argument Type
|
Return Type
|
| abs (x) |
return the absolute value of x |
real or integer |
same as argument |
| round (x) |
return the value of x rounded to the nearest integer |
real or integer |
integer |
| sqr (x) |
return the square of x |
real or integer |
same as argument |
| sqrt (x) |
return the positive square root of x |
real or integer
(non-negative) |
real
(non-negative) |
| trunc (x) |
return the integral part of x |
real or integer |
integer |
| random (x) |
return a random number that is greater than or equal to zero but less than x |
integer
(non-negative) |
integer
(non-negative) |
| randomize |
initializes the built-in random number generator |
--- |
--- |
Remark :
In order to have the random numbers, the standard procedure randomize should be called before calling the function random (x), otherwise, the same sequence of numbers would be generated. The function of the procedure randomize is to initialize the built-in random number generator.
|