Free pascal standard data types, built-in functions and other necessary knowledge
1. Real type integer type
Real type: numerical range: number of bytes: Effective digits
real:2.9e-39..1.7e38:6:11..12
single:1.5e-45..3.4e38:4:7.. 8
double:5.0e-324..1.7e308:8:15..16
extended:3.4e-4951..1.1e4932:10:19..20< /p>
comp:-2**63+1..2**63-1:8:19..20
Integer type: Value range: Number of bytes: Format< /p>
shortint:-128..127:1: signed 8-bit
integer:-32768..32767:2: signed 16-bit
longint: -2147483648..2147483647:4: signed 32-bit
byte:0..255:1: unsigned 8-bit
word:0..65535:2: unsigned 16 bits
longword:0..4294967295:4
Cardinal:either word, longword or qword:size 2/4/8
Int64:-9223372036854775808 ..9223372036854775807:8
QWord:0..18446744073709551615:8
2. Commonly used pascal built-in functions and procedures
Standard constants False, Maxint, True ,Maxlongint,Pi
Standard types Boolean, Char, Real, Integer, Longint, etc.
Standard functions Abs, Arctan, Chr, Cos, Eof, Eoln, Exp, Ln, Odd,Ord,Pred,Round,Sin,Sqr,Sqrt,Succ,Trunc
Standard procedure Dispose,Get,New,Pack,Page,Put,Read,Readln,Reset,Rewrite,Unpack,Write, Writeln
Standard file Input, Output
(1) Standard function whose independent variable must be an integer:
(A) Precursor function: Pred(x ), the function result type is integer, such as: Pred(4)=3
(B) Successor function: Succ(x), the function result type is integer, such as: Succ(4)=5
(C) Odd function: odd(x), the result is Boolean. For example: Odd(13)=True
(D) Character function: Chr(x) where x is the ASCII code and the function result is character type. For example: Chr(65)='A'
(2) The independent variable is an integer (or real type), but the function value type is a standard function of real type;
( A) Square root function: Sqrt(x)
(B) Integer function: Int(x) Take the integer part, such as: INT(3.85)= 3.0
(C) Decimal function :Frac(x)
(D) Sine function: Sin(x)
(E) Cosine function: Cos(x)
(F) Anyway Tangent function: Arctan(x), unit is radians
There is no tangent function in Pascal, use Sin(x)/Cos(x) instead
(G) Exponential function: Exp( x), that is to find ex
(H) logarithmic function: Ln(X), that is to find the natural logarithm of x logex
Power operation ∵ xy=eylnx, ∴ xy = Exp(y*ln(x)
Note: In FreePascal, the expression of power: xy==power(x,y) or xy=x**y
(I )Random function: Random(x:word), when there is no x, the function value takes a random decimal number between [0,1); when there is x and it is Word type, the function value takes a random integer between [0,x) . Add in front: Randomize statement.
(J) Pi function PI=3.1415926536
(3) The independent variable is an integer type (or real type), but the function value type is the same as x.
(A)Abs(x): Absolute value function, such as: Abs(-2)=2 Abs(-2.0)=2.0000000000E+00
(B)Sqr(x): Square Functions such as: Sqr(4)=16 Sqr(4.0)= 1.6000000000E+01
(4) The independent variable is an integer (or real type), but the function value type is an integer standard Function
(A)Trunc(x): Take the integer part, such as: Trunc(3.85)=3
(B)Round(x): Round, such as: Round(2.8 )=3 Round(-2.8)=-3
(5) Add 1 function: inc(x) For example: inc(5)=6,inc(5,8)=13
(6) Subtract 1 function dec(x) such as: dec(5)=4 dec 5,3)=2
File function:
(1) Eof( f) or Seekeof(f) does not read the end-of-file character "Chr(26)" or "Ctrl+Z", the function value is false; when the end-of-file character is read, the function value is true;
(2) When Eoln(f) or SeekEolf(f) does not read the line end character "Chr(13)", the function value is false; when it reads the line end character or file end character, the function value is true; p>
Character function
(1) Convert lowercase letters to uppercase letters Upcase('x'), such as: Upcase ('a')='A'
( 2) Precursor function: Pred('x'), the function result is character type, such as: Pred('4')='3'
(3) Successor function: Succ('x') , the function result is character type, such as: Succ('A')='B'
(4) Ordinal function: Ord('x'), the function result is integer type, find the ASCII corresponding to the character code, such as: Ord('A')=65
(5) Character function: Chr(x), x is an integer type, the function result is a character type, find the character corresponding to the ASCII code, such as :Chr(65)='A'
String function
(1) Find the length
Definition: function Length(S: String): Integer ;
(2) Copy substring copy
Definition: function Copy(S: String; Index: Integer; Count: Integer): String;
Note :S is an expression of string type. Index and Count are integer expressions. Copy returns a substring in S starting from Index and Count characters long.
(3) Insert substring insert
Definition: procedure Insert(Source: String; var S: String; Index: Integer);
Note: Source Is an expression of string type. S is an arbitrary length string type variable. Index is an integer expression. Insert inserts Source into Index at S. If the length of the resulting string is greater than 255, characters after 255 will be removed.
(4) Delete substring delete
Definition: procedure Delete(var S: String; Index: Integer; Count:Integer);
Note: S Is a string type variable. Index and Countare are integer expressions. Delete deletes Count characters starting from Index in S. If Index is greater than the length of S, no characters are deleted; if Count is greater than the actual number of characters starting from Index in S, the actual number of characters is deleted.
(5) Convert string to numerical value val
Definition: procedure Val(S; var V; var Code: Integer);
Here: S Is a string type variable composed of a series of numeric characters;. V is an integer or real variable; Code is an Integer variable
Note: Val converts S into its numerical form.
(6) Convert numerical value to string str
Definition: procedure Str(X [: Width [: Decimals ]]; var S:string); Note: Convert numerical value into string form.
(7) Find the starting position pos of the substring
Definition: function Pos(Substr: String; S: String): Byte;
Note: Substr and S string type expressions. Pos searches Substr in S and returns an integer value. This value is the position of the first character of Substr in S. If Substr is not found in S, Pos returns 0.
(8) Characters are completely concatenated + concatenated
Definition: The operator plus sign + concatenates two strings together.
(9) String compression space concatenation -
Definition: operator minus sign - after removing the last space of the first string, concatenate the two strings together.
(10) Fill the array with initial values ??in batches, Fillchar(x,sizeof(x),0), fill 0 into the x array, sizeof(x) represents the number of filled in< /p>
3. Three important exit statements
HALT ends the program and returns to the operating system
EXIT ends the process or function and returns to the calling place (same as in the main program) HALT)
BREAK is used to exit the loop statement (CONTINUE is used to continue the current loop)