O'Reilly logo

REALBasic: TDG, 2nd Edition by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Numbers

REALbasic has three numeric datatypes: integer, single, and double. An integer may be any whole number between -2147483648 and 2147483647, inclusive. An integer literal has no decimal point. Single and double are both floating-point types; a single is accurate to about 7 decimal digits, a double is accurate to about 15 digits. A floating-point literal has a decimal point, and is assumed to be a double.

Coercion of Numbers

Under certain circumstances, REALbasic performs an implicit coercion: it takes a numeric value of one type (integer, single, or double) and changes it to a different type. Care must be taken not to perform such implicit coercion accidentally, as possibly surprising numeric results may ensue. Also, calculations that involve coercion are slower than those that don’t. But implicit coercion can be a good thing, since it is REALbasic’s only method of numeric coercion.

When a numeric value is assigned to a reference with a numeric datatype, it is implicitly coerced, if necessary, to the declared datatype of the reference. For example, to get the integral part of a floating-point value, you can assign the value to an integer:

dim i as integer
i = 123.456// 123

When a floating-point value is coerced to an integer, if the value’s integral part is out of range, the result is the maximum positive or minimum negative integer:

dim i as integer
i = 2147483648.0// 2147483647

But when a calculated integer value is out of range, it wraps around from the opposite end of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required