The main primitive data types in Whiley are:
- Booleans are denoted by the type
bool. This is the simplest of the primitive data types, and has only two possible values:trueorfalse. - Integers are denoted by the type
int. Integers in Whiley are unbounded. This means that, in theory at least, a variable of typeintcan take on any possible integer value; this differs from languages like Java, which imposed range limits based on the underlying number presentation (typically 32-bit two’s complement). - Reals are denoted by the type
real. Reals in Whiley are unbounded rationals. This means that, in theory at least, a variable of typerealcan take on any possible rational value; again, this offers significantly better precision than, for example,floatordoublenumbers in Java (which uses IEEE 754).
The following simple Whiley program illustrates these data types in action:
void System::main([string] args):
i = 123456789101112131415161718
r = 1234567.192849103954720300939
out.println(str(i))
out.println(str(r))
This program behaves as expected: by printing out the numbers exactly as shown. Observe that neither of these numbers can be stored in a Java variable of type float or double without losing precision.
Finally, since we have unbound rationals, it is always valid to assign a variable of type int to one of type real and, furthermore, Whiley guarantees there will be no loss of precision. Again, this differs from Java where such assignments may result in a loss of precision (e.g. assigning Java int to float).

Popular Posts