1.2 Basic Types

Turing has several basic types we can use to store things in our programs. In this section we will look at constants of these types. There are two main types we can use for storing numbers. The int type is used to store integers. The real type is used to store floating point numbers. The following program uses predefined constants (maxint and minint) to show the range of allowable integers in a Turing program:

put "The largest integer is ", maxint
put "The smallest integer is ", minint 

This program produces the following output:

The largest integer is 2147483647
The smallest ineger is -2147483647

You can use much larger values for reals. For really large (or small) numbers Turing can use scientific notation. Turing uses the letter E (or e) to represent powers of 10. For example,

Reals have 16 digits of accuracy and the exponents (number after E) have a range of at least -38 to 38. You do not have to put a number before or after a decimal. The number after E in scientific notation must be an integer. Commas and spaces are not allowed in any numbers (eg. both 10,853 and 10 853 are invalid).

The int type is known as an ordinal type. For any given integer (with the exception of maxint and minint) there is exactly one value that immediately precedes it and exactly one value that immediately follows it. The real type is not an ordinal type. Why? What number follows 10.8? Is it 10.81, 10.801, 10.8001,... ? For any number you suggest there is always another number between it and 10.8.

If we wish to store characters we use the string type. Any character you can type on the keyboard can be put in a string. Strings start and end with double quotes. Here are some strings:

To store only 1 character you can use the char type. Chars start and end with single quotes. Here are some chars:


Exercise 1.2

  1. Classify each constant as real, int, string or illegal. If it is illegal, justify your answer.
    1. -0.0123
    2. 5E7
    3. "legal?!?"
    4. .73
    5. "valid "string"?"
    6. 5E6.2
    7. 33,146
    1. -6E-7
    2. -0
    3. $7.21
    4. "$7.21"
    5. +45.2
    6. 8.29E
    7. 'abcde'
  2. Rewrite each value in two other ways, using E notation.
    1. 0.000577
    2. 62119
    1. -740000
    2. -0.0000002
  3. Rewrite without using E notation.
    1. 35E-3
    2. 0.077E4
    3. -1.2E-4
    1. -5300e-1
    2. 9.9E0
    3. -4.08e6