[ Prev | Index | Next ]
Japanese English

Data Types

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

Sponsored Link

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).
Integers 64bit
Approx. 18 digits.
For handling integers. Uses 64-bit binary processing, allowing for fast calculations.
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:

- Execution Result -


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:

- Execution Result -


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:

- Execution Result -


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:

- Execution Result -


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:

- Execution Result -


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:

- Execution Result -


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:

- 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:

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:

- Execution Result -

3.3333333... (approximately 16 digits)

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

- 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:

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 article!
» How we translated this article

Sponsored Link

Japanese English

Software Updates: Command Expansion in RINEARN Graph, and English Support in VCSSL
2024/02/05 - We updated our apps. This updates include "Enhancing the Command-Line Features of RINEARN Graph" and "Adding English Support to VCSSL." Delves into each of them!

Inside the Repetitive Execution Speedup Impremented in Vnano Ver.1.1
2024/01/17 - Delves into the update in Vnano 1.1 from a developer's viewpoint, providing detailed insights into the specific improvements made to the internal structure of the script engine.

Scripting Engine Vnano Ver.1.1 Released: Dramatic Speed Improvement for Repetitive Executions of the Same Content
2023/12/22 - Released the Vnano script engine Ver.1.1. In this version, we've made significant enhancements in processing speed by reducing the overhead of handling requests. Explains the details.

Updated Contents
Circular Wave Animation

Draws the circular wave as 3D animation, under the specified wave parameters.
Sine Wave Animation

Draws the sine wave as animation, under the specified wave parameters.
Tool For Converting Units of Angles: Degrees and Radians

A GUI tool for converting the angle in degrees into radians, or radians into degrees.
Connector Fatal Exception - Specification
The unchecked exception thrown when errors have occurred, caused by incorrect implementations (might be bugs).
Connector Exception - Specification
The checked exception thrown when errors have occurred, cause by expected normal problems.