Difference between revisions of "Int"
From Free Pascal wiki
Jump to navigationJump to searchm (Fixed syntax highlighting; deleted category included in page template) |
(structure, blow up) |
||
Line 1: | Line 1: | ||
{{Int}} | {{Int}} | ||
− | Function '''Int''' returns the integer part of the argument. | + | The [[Function|<syntaxhighlight lang="pascal" inline>function</syntaxhighlight>]] '''{{Doc|package=RTL|unit=system|identifier=int|text=<syntaxhighlight lang="delphi" inline>Int</syntaxhighlight>}}''' returns the [[Integer|integer]] part of the argument. |
+ | It is an [[UCSD Pascal]] extension supported by the [[FPC]] as an <syntaxhighlight lang="delphi" inline>InternProc</syntaxhighlight>. | ||
− | + | == Behavior == | |
− | <syntaxhighlight lang=pascal> | + | <syntaxhighlight lang="delphi" inline>Int</syntaxhighlight> has effectively the following signature ({{gitlab|blob|FPC|https://gitlab.com/freepascal.org/fpc/source/blob/release_3_2_0/rtl/inc/mathh.inc#L116|actual declaration}} uses the compiler intrinsic): |
− | function Int(X: Real): Real; | + | <syntaxhighlight lang="pascal">function Int(X: Real): Real;</syntaxhighlight> |
− | </syntaxhighlight> | + | <syntaxhighlight lang="delphi" inline>X</syntaxhighlight> must be a [[Real|real]]-type expression. |
+ | The result is the integer part of X, rounded toward zero ''as a <syntaxhighlight lang="pascal" inline>real</syntaxhighlight> value''. | ||
+ | It is ''semantically'' equivalent to <syntaxhighlight lang="pascal" inline style="whitespace: nowrap;">Trunc(X) * 1.0</syntaxhighlight> (<syntaxhighlight lang="pascal" inline>Trunc</syntaxhighlight> would cause an error if there did not exist an appropriate <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> value). | ||
− | See also | + | == Application == |
− | * [[Frac]] | + | * <syntaxhighlight lang="delphi" inline>Int</syntaxhighlight> is used to do a [[Trunc|<syntaxhighlight lang="pascal" inline>Trunc</syntaxhighlight>]] without leaving the domain of <syntaxhighlight lang="pascal" inline>real</syntaxhighlight> numbers. This speeds up things and virtually allows a larger range of permissible values. For an example see {{gitlab|blob|FPC|release_3_2_0/rtl/objpas/math.pp#L2476-2496|the implementation of}} {{Doc|package=RTL|unit=math|identifier=fmod|text=<syntaxhighlight lang="delphi" inline>math.FMod</syntaxhighlight>}}. |
− | * [[Round]] | + | |
− | * [[Trunc]] | + | == See also == |
+ | * [[Frac|<syntaxhighlight lang="delphi" inline>Frac</syntaxhighlight>]] – return fractional part as <syntaxhighlight lang="pascal" inline>real</syntaxhighlight> | ||
+ | * [[Round|<syntaxhighlight lang="pascal" inline>Round</syntaxhighlight>]] – return rounded <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> value | ||
+ | * [[Trunc|<syntaxhighlight lang="pascal" inline>Trunc</syntaxhighlight>]] – return truncated <syntaxhighlight lang="pascal" inline>integer</syntaxhighlight> value |
Revision as of 00:41, 29 January 2022
│
English (en) │
русский (ru) │
The function
Int
returns the integer part of the argument.
It is an UCSD Pascal extension supported by the FPC as an InternProc
.
Behavior
Int
has effectively the following signature (actual declaration uses the compiler intrinsic):
function Int(X: Real): Real;
X
must be a 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).
Application
Int
is used to do aTrunc
without leaving the domain ofreal
numbers. This speeds up things and virtually allows a larger range of permissible values. For an example see the implementation ofmath.FMod
.