Int: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Int
| Old | New | Line | |
|---|---|---|---|
| 1 | + | The [[Function|function]] **[`Int`](https://www.freepascal.org/docs-html/rtl/system/int.html)** returns the [[Integer|integer]] part of the argument. It is an [[UCSD Pascal]] extension supported by the [[FPC]] as an `InternProc`. | |
| 2 | + | ||
| 3 | + | ## Behavior | |
| 4 | + | ||
| 5 | + | `Int` has effectively the following signature ([actual declaration](https://gitlab.com/freepascal.org/fpc/source/blob/release_3_2_0/rtl/inc/mathh.inc#L116) uses the compiler intrinsic): | |
| 6 | + | ||
| 7 | + | ``` pascal | |
| 8 | + | function Int(X: Real): Real; | |
| 9 | + | ``` | |
| 10 | + | ||
| 11 | + | `X` must be a [[Real|real]]-type expression. The result is the integer part of X, rounded toward zero *as a `real` value*. It is *semantically* equivalent to `Trunc(X) * 1.0` (`Trunc` would cause an error if there did not exist an appropriate `integer` value). | |
| 12 | + | ||
| 13 | + | ## Application | |
| 14 | + | ||
| 15 | + | - `Int` is used to do a [[Trunc]] without leaving the domain of `real` numbers. This speeds up things and virtually allows a larger range of permissible values. For an example see [the implementation of](https://gitlab.com/freepascal.org/fpc/source/blob/release_3_2_0/rtl/objpas/math.pp#L2476-2496) [`math.FMod`](https://www.freepascal.org/docs-html/rtl/math/fmod.html). | |
| 16 | + | ||
| 17 | + | ## See also | |
| 18 | + | ||
| 19 | + | - [[Frac]] – return fractional part as `real` | |
| 20 | + | - [[Round]] – return rounded `integer` value | |
| 21 | + | - [[Trunc]] – return truncated `integer` value | |
| 22 | + | ||
| 23 | + | --- | |
| 24 | + | *From the Free Pascal wiki, page "Int", as it stood on 2022-08-10 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).* |
