|
To access the contents, click the chapter and section titles.
Learn Pascal in a Three Days (2nd Ed.)
Chapter 2
|
MAXINT | the maximum positive integer |
-(MAXINT+1) | the maximum negative integer |
Again, the value of MAXINT depends on the implementation.
Real numbers are generally stored in a larger number of bytes than are integers, but they are of limited precision. Fractions such as 0.333333 and 0.666666 can never be as precise as the exact values 1/3 and 2/3, regardless of how many digits are used to represent the number. For this reason, it is not recommended to test two real numbers for equality. Instead, it would be better to test to see if the difference between the two numbers is less than some specific small amount.
In Turbo Pascal, there are additional numeric types, which are introduced in the following section.
There are additional integer types (including the type INTEGER) in Turbo Pascal. They are shown in Table 2-1 along with their storage sizes and the maximum range of values that can be represented in each.
In one byte, you can store either a SHORTINT or a BYTE. The BYTE is actually an unsigned SHORTINT, which means that it can hold only positive numbers. As you can see in the table, the maximum range of values for a type is doubled when the sign is not used. The same applies to the types INTEGER and WORD, as the WORD is a positive integer of doubled maximum range.
Data Type | Size (in bytes) | Range |
---|---|---|
SHORTINT | 1 | from -128 to +127 |
BYTE | 1 | from 0 to 255 |
INTEGER | 2 | from -32768 to +32767 |
WORD | 2 | from 0 to 65535 |
LONGINT | 4 | from -2,147,483,648 to +2,147,483,647 |
The LONGINT is the largest integer that can be represented in Turbo Pascal. You can test its value by displaying the value of the predefined constant MAXLONGINT as follows:
WRITELN(MAXLONGINT);
Notice that the negative range of any signed type exceeds the positive range by one (e.g., +127 and -128). This is because zero is counted with the positive numbers.
CAUTION: The commas used here to express large numbers are used only for readability. You will neither see them in the output of a program, nor are they accepted as a part of literal constants. So, the number 2,147,483,647 must be used as 2147483647.
In Turbo Pascal, there are also additional real types (including the type REAL) as shown in Table 2-2. For real numbers, a new column is added to the table to describe the accuracy of a number as the maximum number of precise digits.
Data Type | Size (in bytes) | Precision (up to) | Range |
---|---|---|---|
SINGLE | 4 | 7 digits | from 0.71E-45 to 3.4E+38 |
REAL | 6 | 11 digits | from 2.94E-39 to 1.7E+38 |
DOUBLE | 8 | 15 digits | from 4.94E-324 to 1.79E+308 |
EXTENDED | 10 | 19 digits | from 3.3E-4932 to 1.18E+4932 |
COMP | 8 | integers only | ±9.2E+18 |
If you examine the range of the type SINGLE, you will find that it is pretty close to that of the type REAL, especially in the area of the very large numbers. The main difference between the two lies in the economical storage of the SINGLE type (4 bytes compared to 6), which comes at the expense of precision (7 digits compared to 11). Real number types other than REAL are not available unless a math coprocessor is used. The type COMP actually belongs to the set of integers, as it does not accept fractions, but it is usually mentioned among reals as it requires the use of a math coprocessor.
Previous | Table of Contents | Next |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |