|
|
|
The Basic TypesThese are the basic types in Pike:
They are basic in the sense that data items of these data types can't contain other data items. When a data item of a basic type is stored in a variable, it is the data item itself that is stored, and not just a reference to it, as explained earlier. The Data Type intInteger values can be written in several ways:
You can use normal arithmetic operations, such as addition and multiplication, with integers, but you can also consider integers as sequences of bits and, apply bitwise operations on them. For example, the integer value 247 is stored internally as the sequence of bits 1111011, and you could left-shift it three positions with the expression 247 << 3, giving the bit pattern 1111011000, which is equal to 1976. Integers in Pike can be very large. For small integers (usually less than 2 billion or so), Pike will use the computer's own, hardware-supported way of representing integers. For larger integers, Pike will use "bignums". These are slower, but can be arbitrarily large. Just like the smaller integers, bignums are represented exactly, without any rounding errors. As a programmer, you will usually not need to worry about the difference between bignums and smaller integers. There may however be some operations, for example certain methods in certain modules, that cannot handle bignums but work with smaller integers. Some operations that you can apply to integers:
The Data Type floatReal numbers, which are numbers that can have a fractional part, such as 18.34 and -1000.03, are represented in the computer as floating-point numbers. Floating-point numbers can be used to represent very large numbers, but with limited precision. The number of significant digits is the same, no matter the magnitude of the value. You can write floating-point values in two ways, as usual with decimals, or in exponential form with an e: 3.1415926535 -123.0001 12.0 1.0e6 // 1.0 times 10 to the power of 6, i. e. one million 2.0e-6 // 2.0 times 10 to the power of -6, i. e. two one-millionths -1.0e-2 // Minus one hundredth Some operations that you can apply to floating-point numbers:
The Data Type stringStrings are sequences of characters, and are written within double quotes (") in Pike: "scorch" "Hello world!" "Woe to you, oh Earth and Sea" "" The last one is the empty string. Special characters, such as the double quote character, need to be preceded by a backslash character (\):
Here are some examples of strings: "One line\nAnother line\nA third line" "Strings are written within \" characters." You can use character codes instead of the characters themselves. If you write \d followed by a decimal (that is, normal base 10) number, it will be replaced by the character with that character code. The same goes for \x followed by a hexadecimal (base 16) number, and a single \ followed by an octal (that is, base 8) number. The \0 is actually an example of this. These four strings are identical: "Hello world" "Hello \d119orld" "Hello \x77orld" "Hello \167orld" Strings in Pike are what we call "shared", which means that if two or more strings contain exactly the same characters, there will still be only one copy of it. Some operations that you can apply to strings:
Pike has many powerful built-in operations for working with strings. Read more about those in the chapter about string handling, below. |
|||||||||