Difference between revisions of "Int"

From Free Pascal wiki
Jump to navigationJump to search
(structure, blow up)
 
Line 5: Line 5:
  
 
== Behavior ==
 
== Behavior ==
<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):
+
<syntaxhighlight lang="delphi" inline>Int</syntaxhighlight> has effectively the following signature ({{gitlab|blob|FPC|release_3_2_0/rtl/inc/mathh.inc#L116|actual declaration}} uses the compiler intrinsic):
 
<syntaxhighlight lang="pascal">function Int(X: Real): Real;</syntaxhighlight>
 
<syntaxhighlight lang="pascal">function Int(X: Real): Real;</syntaxhighlight>
 
<syntaxhighlight lang="delphi" inline>X</syntaxhighlight> must be a [[Real|real]]-type expression.
 
<syntaxhighlight lang="delphi" inline>X</syntaxhighlight> must be a [[Real|real]]-type expression.

Latest revision as of 22:47, 10 August 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 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 math.FMod.

See also

  • Frac – return fractional part as real
  • Round – return rounded integer value
  • Trunc – return truncated integer value