Sign in Join
Wiki copytemporary

Real

Deutsch · English · Français · Русский

real is a standard type of the Pascal programming language. Despite its name, the data type real only provides a “reasonable approximation” of ℝ, the set of real numbers. For example the real number $\sqrt{2}$ may have the real value of 1.4 in Pascal.

usage

Floating-point literals can be assigned to real variables.

pascal
program realDemo(input, output, stderr);

var
    r: real;

begin
    r := 0.0; { r becomes zero }
    writeLn(r, ' ', r:8:4);
    
    r := 1e2; { r becomes 1*(10^2) [a hundred] }
    writeLn(r, ' ', r:8:4);
    
    r := r / r; { r becomes one }
    writeLn(r, ' ', r:8:4);
end.

real, like all floating-point types, supports / division operator, while integer types support div-operator.

internal representation

The internal representation of the type real (i.e. number of bytes and byte ordering) and the resulting range and precision are platform dependent.

Quote from the “FreePascal Programmer's Manual” (Chapter 8.2.5 Floating point types):

Contrary to Turbo Pascal, where the real type had a special internal format, under Free Pascal the real type simply maps to one of the other real types. It maps to the double type on processors which support floating point operations, while it maps to the single type on processors which do not support floating point operations in hardware.

alternatives

Instead of specifying real in your code, write ValReal, a type alias defined by the System unit. It automatically maps to the largest available floating point type available: single, double or extended.

see also


From the Free Pascal wiki, page "Real", as it stood on 2023-01-25 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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.