Difference between revisions of "IEEE 754 formats"
(deduplicated from Double; use <syntaxhighlight> instead of <source>) |
|||
Line 1: | Line 1: | ||
{{Single}} | {{Single}} | ||
− | + | <syntaxhighlight lang="pascal" enclose="none">single</syntaxhighlight> and <syntaxhighlight lang="pascal" enclose="none">double</syntaxhighlight> are Pascal's [[Data type|data types]] implementing the platform-dependent [[Real|<syntaxhighlight lang="pascal" enclose="none">real</syntaxhighlight>]]. | |
+ | Both are implemented according IEEE standard 754, where <syntaxhighlight lang="pascal" enclose="none">single</syntaxhighlight> is “single-precision” and <syntaxhighlight lang="pascal" enclose="none">double</syntaxhighlight> is “double-precision”. | ||
− | + | == <syntaxhighlight lang="pascal" enclose="none">single</syntaxhighlight> == | |
− | + | ||
− | + | {| class="wikitable" | |
− | + | | value range || 1.5E-45 .. 3.4E38 | |
− | Assigning other values will result in error messages from the compiler when the program is compiled, and the compile will be aborted. That is, the executable program is not created. | + | |- |
+ | | accuracy || 6-9 significant decimal digits precision | ||
+ | |- | ||
+ | | memory requirement || 4 bytes or [[32 bit]]s | ||
+ | |- | ||
+ | | property || The single- data-type data field can hold floating-point values and signed and unsigned integer values. | ||
+ | Assigning other values will result in error messages from the compiler when the program is compiled, and the compile will be aborted. | ||
+ | That is, the executable program is not created. | ||
+ | |} | ||
Definition of a data field of data type Single: | Definition of a data field of data type Single: | ||
− | < | + | <syntaxhighlight lang="pascal> |
− | var | + | var |
− | s : Single ; | + | s: Single; |
− | </ | + | </syntaxhighlight> |
Examples of assigning valid values: | Examples of assigning valid values: | ||
− | < | + | <syntaxhighlight lang="pascal> |
− | s : = - 123.45678 ; | + | s := -123.45678; |
− | s : = 0 ; | + | s := 0; |
− | s : = 123.45678 ; | + | s := 123.45678; |
− | </ | + | </syntaxhighlight> |
Examples of assigning invalid values: | Examples of assigning invalid values: | ||
− | < | + | <!-- no syntaxhighlight, because this is a counter-example --> |
− | s : = '-123.45678' ; | + | <pre> |
− | s : = '0' ; | + | s := '-123.45678'; |
− | s : = '123.45678' ; | + | s := '0'; |
− | </ | + | s := '123.45678'; |
+ | </pre> | ||
The difference between the two examples is that the upper example is the assignment of Integer and FloatingCommand literals, while the assignment of the lower example is literals of the String type. | The difference between the two examples is that the upper example is the assignment of Integer and FloatingCommand literals, while the assignment of the lower example is literals of the String type. | ||
− | == Binary floating-point format== | + | === Binary floating-point format === |
Any value stored as a single requires 32 bits, formatted as shown in the table below: | Any value stored as a single requires 32 bits, formatted as shown in the table below: | ||
Line 48: | Line 58: | ||
|- | |- | ||
| 22 to 0 | | 22 to 0 | ||
+ | | Fraction f of the number 1.f | ||
+ | |} | ||
+ | |||
+ | == <syntaxhighlight lang="pascal" enclose="none">double</syntaxhighlight> == | ||
+ | |||
+ | Any value stored as a double requires 64 bits, formatted as shown in the table below: | ||
+ | |||
+ | {| class="wikitable" | ||
+ | ! Bits | ||
+ | ! Usage | ||
+ | |- | ||
+ | | 63 | ||
+ | | Sign (0 = positive, 1 = negative) | ||
+ | |- | ||
+ | | 62 to 52 | ||
+ | | Exponent, biased by 1023 | ||
+ | |- | ||
+ | | 51 to 0 | ||
| Fraction f of the number 1.f | | Fraction f of the number 1.f | ||
|} | |} |
Revision as of 15:00, 28 March 2018
│
English (en) │
single
and double
are Pascal's data types implementing the platform-dependent real
.
Both are implemented according IEEE standard 754, where single
is “single-precision” and double
is “double-precision”.
single
value range | 1.5E-45 .. 3.4E38 |
accuracy | 6-9 significant decimal digits precision |
memory requirement | 4 bytes or 32 bits |
property | The single- data-type data field can hold floating-point values and signed and unsigned integer values.
Assigning other values will result in error messages from the compiler when the program is compiled, and the compile will be aborted. That is, the executable program is not created. |
Definition of a data field of data type Single:
var
s: Single;
Examples of assigning valid values:
s := -123.45678;
s := 0;
s := 123.45678;
Examples of assigning invalid values:
s := '-123.45678'; s := '0'; s := '123.45678';
The difference between the two examples is that the upper example is the assignment of Integer and FloatingCommand literals, while the assignment of the lower example is literals of the String type.
Binary floating-point format
Any value stored as a single requires 32 bits, formatted as shown in the table below:
Bits | Usage |
---|---|
31 | Sign (0 = positive, 1 = negative) |
30 to 23 | Exponent, biased by 127 |
22 to 0 | Fraction f of the number 1.f |
double
Any value stored as a double requires 64 bits, formatted as shown in the table below:
Bits | Usage |
---|---|
63 | Sign (0 = positive, 1 = negative) |
62 to 52 | Exponent, biased by 1023 |
51 to 0 | Fraction f of the number 1.f |