[ Team LiB ] |
13.2 Integer, Real, and NumberThe integer and real datatypes are the numeric classes. 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, which, as everyone knows, is 229-1. Any integer value outside this range is implicitly coerced to a real. 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 in any case it will always be a real. For example: 1e2 -- rewritten: 100.0 2.1e26 -- rewritten: 2.1E+26 You can't include a comma as a thousands separator in a literal number. The class number is purely for purposes of coercion. In some situations you can use it to ask AppleScript to coerce to whichever numeric datatype, integer or real, is appropriate. This is nice because it saves you from having to worry about which is appropriate. class of ("1" as number) -- integer class of ("1.1" as number) -- real
An integer is four bytes. 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, since 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 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 used numeric classes, transparently coerced to integer or real before you get hold of them; these include fixed, extended real, and so forth. For a full list, see Appendix A. |
[ Team LiB ] |