Data Types

Variables and values have several types, depending on the kind of data. Here, we will discuss the data types in VCSSL.

- Table of Contents -

What are Data Types?

In programming, data, whether stored in variables or written directly in expressions, comes in various types. These categories are referred to as data types. In VCSSL, the data type of a variable needs to be determined at declaration and cannot be changed afterward (this is known as static typing).

Each data type can handle certain kinds of values and not others, and they also differ in the operations they support. For instance, the 'int' type is used for integers and cannot handle strings. Conversely, the 'string' type, used for text, cannot perform arithmetic operations. Therefore, it's important to choose an appropriate data type for the values you intend to store when declaring a variable.

The data types supported in VCSSL include:

Type Values Capacity Details
string Strings Arbitrary length For storing text (character-string).
int
or
long
Integers 64bit
Approx. 18 digits.
For handling integers. Uses 64-bit binary processing, allowing for fast calculations.
float
or
double
Floating-Point Numbers 64bit
Approx. 15 digits.
For handling decimals. Uses 64-bit binary processing but lacks precision, causing calculation errors in the last few digits.
complex Complex numbers float
x 2 values
For handling complex numbers. Contains float type real and imaginary values.
varint Integers Arbitrary digits For handling integers with very high precision and can handle extremely long digits. However, it is much slower than the int type.
varfloat Floating-Point Numbers Arbitrary digits For handling decimals with very high precision and can handle extremely long digits. However, it is slower than the float type.
varcomplex Complex numbers varfloat
x 2 values
For handling complex numbers with varfloat type real and imaginary values.
bool true / false Binary choice For handling outcomes of conditional evaluations. The values true and false can be interpreted as YES and NO.
struct Structures - For handling a collection of variables of arbitrary types and quantities.

* Note: In other programming languages, the capacity of 'long' (or 'long int,' etc.) and 'double' types is often double (or more) compared to 'int' and 'float' types. In VCSSL, all these types have 64-bit precision, so there's no need for distinction. The support for 'long' and 'double' types is mainly for code portability with other languages.

Using "int" Type

As an example, let's use an 'int' type variable to store an integer:

IntToInt.vcssl

- Execution Result -

1

Running this program will display "1" on the VCSSL console.

What happens if we assign a non-integer value to an 'int' type variable? Please try running the following program:

FloatToInt.vcssl

- Execution Result -

2

Executing this program displays "2" on the console. The number with a decimal point "2.883" was forcibly converted to an integer by truncating the decimal part. As such, if a variable is assigned a value it cannot handle, it converts the value into a form it can handle.

This rule is known as "implicit type conversion." Note that if an unconvertible value is assigned, an error is outputted, and the program is forcibly terminated.

To handle numbers with decimal points (real numbers, floating-point numbers), you should use the 'double' or 'float' type. This can be written as follows:

FloatToFloat.vcssl

- Execution Result -

2.883

Running this program correctly displays "2.883" on the VCSSL console.

Cast Operation (Explicit Type Conversion)

In the earlier example, we discussed how assigning a number with a decimal point to an integer type forcibly converts it to an integer. This conversion can also be explicitly performed anywhere in the program:

CastFloatToInt.vcssl

- Execution Result -

2

Running this program will display "2" on the VCSSL console.

Pay attention to the "(int)" part of this program. This notation, where a data type is enclosed in parentheses, is called a cast operator. The cast operator forcibly converts the value immediately to its right into a specified type. In the example above, "2.883" was forcibly converted to an integer, resulting in "2."

Using "complex" Type

In VCSSL, the complex type is available for storing and handling complex numbers:

ComplexAdd.vcssl

- Execution Result -

(1.0,2.0)

Executing this program results in "(1.0, 2.0)" being displayed on the VCSSL console.

Here, "I" represents the imaginary unit, which is automatically defined by the system.

Multiplying a number with a decimal point (or a float type variable) by "I" creates an imaginary number. In this example, the value represents a complex number 1 + 2i mathematically.

To extract the real and imaginary parts of a complex number in VCSSL, use the "re" and "im" functions:

ComplexRe.vcssl

- Execution Result -

1.0

Running this program displays "1.0" on the VCSSL console, indicating the real part of 'c'.

Using the "im" function instead would display the imaginary part, "2.0".

Using Variable Precision Variables

In addition to the finite-precision double and float types for storing numbers with decimal points, VCSSL also provides the "varfloat" type, which allows for arbitrary precision.

This type allows you to specify the number of digits to use without limit and can even change the precision during execution. The precision is controlled by calling the "digit" function in your program:

VarfloatDiv.vcssl

- Execution Result -

3.33333333... (up to 100 digits)

Executing this program results in an output of "3.33333333c" up to 100 digits.

Also, the "digit" function returns the set number of digits. You can utilize this property by calling the "digit" function with no arguments to retrieve the current operational precision:

GetDigit.vcssl

Variable Precision Numerical Literals

In the program shown in the two sections above, numbers like "10.0vf" were used. The "vf" suffix indicates that the number is of the varfloat type.

Normally, numbers written directly in an expression (referred to as "literals") are automatically assigned appropriate data types. However, care is needed when using numerical literals in the expression in which varfloat or varint type variables are used. The language standards do not specify whether numerical literals in such expression becomes int/float types or varint/varfloat types, if the literals have no suffix.

Therefore, to ensure a numeric literal is assigned the varfloat type, it is recommended to add "vf" at the end, and "v" at the end for the varint type.

For example, compare the following two programs:

FloatLiteralDiv.vcssl

- Execution Result -

3.3333333... (approximately 16 digits)

Now, let's try adding "vf" at the end of the number:

VarfloatLiteralDiv.vcssl

- Execution Result -

3.3333333... (continues up to 100 digits)

In the first program, the VCSSL console outputs "0.33333..." with approximately 16 digits, indicating that the numeric literals in the expression were treated as double or float types.

In the second program, it outputs "0.33333..." with approximately 100 digits, indicating that the numeric literals were treated as the varfloat type due to the "vf" suffix.

Variable Precision Complex Numbers

Variable precision complex numbers, varcomplex type, are used as follows:

Varcomplex.vcssl

In this program, the VCSSL console outputs "0.33333..." with 30 digits, and on the next line, "0.14285...". Here, VCI represents a variable precision imaginary unit, analogous to the "I" used with complex types. When the re and im functions are used with the varcomplex type, the real and imaginary parts are obtained as varfloat types.

Acknowledgement: We greatly appreciate the cooperation of two ChatGPT AIs in translating this page.
» How we translated this page