Sign in Join
Wiki copytemporary

Basic Pascal Tutorial/Chapter 1/Standard Functions: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
111F - Standard Functions (author: Tao Yue, state: unchanged)
22
33Pascal has several standard mathematical functions that you can utilize. For example, to find the value of sin of pi radians:
44
55``` pascal
66value := sin (3.141592653589793238462643383);
77```
88
99Note that the sin function operates on angular measure stated in radians, as do all the trigonometric functions. If everything goes well, value should become 0.
1010
1111Functions are called by using the function name followed by the argument(s) in parentheses. Standard Pascal functions include:
1212
1313| Function | Description | Argument type | Return type |
1414|----------|----------------------------|-----------------|------------------|
1515| abs | absolute value | real or integer | same as argument |
1616| arctan | arctan in radians | real or integer | real |
1717| cos | cosine of a radian measure | real or integer | real |
1818| exp | e to the given power | real or integer | real |
1919| ln | natural logarithm | real or integer | real |
2020| round | round to nearest integer | real | integer |
2121| sin | sin of a radian measure | real or integer | real |
2222| sqr | square (power 2) | real or integer | same as argument |
2323| sqrt | square root (power 1/2) | real or integer | real |
2424| trunc | truncate (round down) | real or integer | integer |
2525
2626For ordinal data types (integer or char), where the allowable values have a distinct predecessor and successor, you can use these functions:
2727
2828| Function | Description | Argument type | Return type |
2929|----|----|----|----|
3030| chr | character with given ASCII value | integer | char |
3131| ord | ordinal value | integer or char | integer |
3232| pred | predecessor | integer or char | same as argument type |
3333| succ | successor | integer or char | same as argument type |
3434
3535Real is not an ordinal data type! That's because it has no distinct successor or predecessor. What is the successor of 56.0? Is it 56.1, 56.01, 56.001, 56.0001?
3636
3737However, for an integer 56, there is a distinct predecessor — 55 — and a distinct successor — 57.
3838
3939The same is true of characters:
4040
41-```
41+```text
4242 'b'
4343 Successor: 'c'
4444 Predecessor: 'a'
4545```
4646
4747The above is not an exhaustive list, as modern Pascal compilers include thousands of functions for all sorts of purposes. Check your compiler documentation for more.
4848
4949---
5050*From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Standard Functions", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history