Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
aa = { }
aa = {key1:"value", key2: 55, key3: 5+3 }

 


Arrays and associative arrays can also be defined with the following format: 


 

Code Block
aa = {
   Myfunc1: aFunction
   Myval1 : "the value"
}

Invalid Object Return

Many methods (i.e. functions) that return objects can also return Invalid (for example, in cases where there is no object to return). In these cases, the variable accepting the result must be dynamically typed since it may be assigned either type.

The following code will return a type mismatch: a$ is a string that has a string type declaration, and thus it cannot contain Invalid.

 


Code Block
l = []
a$ = l.pop()

Numbers

Dynamic Typing

The following rules determine how integers, doubles, and floats are dynamically typed:

  1. If a constant contains 10 or more digits, or if D is used in the exponent, the number is Double. Adding a # type declaration also forces a constant to be a Double.
  2. If the number is not double precision and it contains a decimal point, the number is a Float. Expressing a number in scientific notation using the E exponent also forces a constant to be a Float.
  3. If neither of the above conditions is true for a constant, the number is an Integer.

Type Conversion

When operations are performed on one or two numbers, the result must be typed as an Integer, Float, or Double. When an addition (+), subtraction (-), or multiplication (*) operation is performed, the result will have the same degree of precision as the most precise operand: For example, multiplying an Integer by a Double will return a number that is a Double.

Only when both operands are Integers will the result be an Integer number. If the result of two Integer operands is outside the 32-bit range, the operation and return will be carried out with Doubles.

Division (/) operates using the same rules as above, except that it can never be carried out at the Integer level: When both operators are Integers, the operation and return will be carried out with Floats.

Comparison operations (e.g. <, >, =) will convert the numbers to the same type before they are compared. The less precise type will always be converted to the more precise type.

Type Conversion and Accuracy

When a Float or Double number is converted to the Integer type, it is rounded down: The largest integer that is not greater than the number is used. This also happens when the INT function is called on a number.

When a Double number is converted to the Float type, it is 4/5 rounded: The least significant digit is rounded up if the fractional part is >=5 (otherwise, it is left unchanged).

When a Float number is converted to the Double type, only the seven most significant digits will be accurate.