When working with real numbers, you can use the already familiar math
module, which contains a large number of built-in functions.
When solving problems, it is often necessary to round real numbers to the nearest integer values. There are three functions for this.
REMEMBER
1 Trunc(x) function - cuts off the fractional part \(x\) and returns an integer value.
2 Floor(x)
- returns the largest integer less than or equal to \(x\) (round down)
3 Ceil(x)
function - returns the smallest integer greater than or equal to \(x\) (round up)
Here are the most useful functions. Some of them are built into Pascal, while the rest are contained in the math
module.
Function |
Description |
Rounding |
round(x)
embedded |
Rounds a number to the nearest integer. If the fractional part of the number is 0.5, then the number is rounded to the nearest whole number. |
trunc(x)
embedded |
Discards the fractional part |
floor(x)
in math |
Rounds a number down ("floor"), thus floor(1.5) == 1 , floor(-1.5) ==  ;-2 |
ceil(x)
in math |
Rounds a number up ("ceiling"), while ceil(1.5) == 2 , ceil(-1.5) ==  ;-1 |
abs(x)
embedded |
Modulo (absolute value). |
Roots, logarithms |
sqrt(x)
embedded |
Square root. Usage: y := sqrt(x) |
power(x, y)
in math |
Raises x to the y power. \(x^y\) |
log2(x)
in math |
Log base 2. |
lnxp1(x)
in math
|
The natural logarithm of (x + 1). |
Trigonometry |
sin(x)
embedded |
Sine of an angle specified in radians |
cos(x)
embedded |
Cosine of an angle specified in radians |
tan(x)
in math |
The tangent of an angle specified in radians |
arcsin(x)
in math |
Arcsine, returns value in radians |
arccos(x)
in math |
Arc cosine, returns value in radians |
arctan(x)
embedded |
Arctangent, returns value in radians |
arctan2(y, x) |
Polar angle (in radians) of the (x, y) point. |