Legato
Legato

GoFiler Legato Script Reference

 

Legato v 1.4j

Application v 5.22b

  

 

Chapter ThreeData Types and Operators (continued)

3.4 Integers Versus Floats

3.4.1 Overview

One of the most fundamental differences in data types relates to integers versus real or floating-point numbers. Integers are very exact, as a value of ‘1’ will always be one. Integers always represent whole numbers. Conversely, real numbers may have precision but are not necessarily exact. A good example is the real number equivalent of 1/3, which results in 0.3333333. This is a “repeating” number that cannot be accurately represented. Integers are appropriate for counting items or indexing lists while floating-point numbers are more suitable for mathematical operations or accounting. Finally, there is a computer oddity with the representation of real numbers. The computer technique for storing and working with floating-point numbers uses a binary mantissa and exponent (similar to scientific notation such as 3.14E10). The translation into and out of decimal format can sometimes lead to minor errors.

When integers and real numbers are mixed in a mathematical operation, data may be lost or otherwise truncated. For example:

int x;

float y;

y = 2.0;

x = 1/y;

In this case, x will contain a value of 0 rather than 0.5 because the result of operation is stored in an integer data type. The real number is truncated to fit the integer specification and information is lost. Therefore, it is essential to pay attention to data types, both those of the variables involved in an operation and that of the variable in which the result is being stored.