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 limit—it's 229-1, two bits short of the four-byte standard—and 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 " ...

Get AppleScript: The Definitive Guide, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.