13.5. Integer, Real, and Number
The integer and real datatypes are the numeric classes. Integers and reals are used for arithmetic calculation (Chapter 15 will discuss AppleScript's operators for this purpose); they are also used, of course, for communicating numeric values between your script and a target application.
class of 1 -- integer class of 1.1 -- real
A literal integer is a series of digits, possibly preceded by a minus sign. The maximum integer is 536870911, positive or negative. Any integer value outside this range is implicitly coerced to a real. This is a very strange limitit's 229-1, two bits short of the four-byte standardand I don't know the reason for it.
A literal real is a series of digits with a decimal point, possibly preceded by a minus sign. You may also use "scientific notation ": that's a number followed by small or capital e, possibly followed by a plus sign or a minus sign, followed by an integer. AppleScript might rewrite a scientific notation number for you, but it remains a real:
1e2 -- rewritten: 100.0 2.1e26 -- rewritten: 2.1E+26
A literal number consisting of too many digits (I have not been able to determine exactly how many is too many) may be rounded, or may be rewritten using scientific notation, at compile time. Alternatively, it may generate an incomprehensible error:
0.123456789012345 -- Syntax error. some object [sic]
You can't include a comma as a thousands separator in a literal number.
The class number is purely for purposes of coercion. See "Number, String, and Date Coercions" in Chapter 14.
A dictionary may occasionally mention a class small integer , which is two bytes (ranging from -32768 to 32767). You can create one by coercion, but there should be little need to do so (though an example appears later in this chapter). Small integers are typically used transparently; they evidently become integers before you get a look at them:
set x to 4 as small integer class of x -- integer class of (ASCII number "a") -- integer, even though the dictionary says "small integer"
There is also a class double integer , which is eight bytes. This is sometimes used when communicating with the system, and seems to be simply a real within the integer range. Again, there should be little need to create one; a double integer in your code is reported as a real. There are other rarely encountered numeric classes, such as fixed, extended real , and so forth, which are reported as (or transparently coerced to) integer or real.