Constants in Scilab

Constants in Scilab can be declared using the assignment operator. In this example, we will illustrate how to declare and use constants in Scilab.

// Declaring a constant
s = "constant";

// Display the constant value
disp(s);

// A constant can be used anywhere a variable can
n = 500000000;

// Perform arithmetic with arbitrary precision
d = 3e20 / n;
disp(d);

// Convert the constant to an integer
disp(int64(d));

// Use the constant in a function that requires a specific type
// For example, sin function expects a double
disp(sin(n));

To run this Scilab code, simply copy and paste it into the Scilab console or save it into a file with a .sce extension and execute it.

Expected output:

constant
6.E+11
600000000000
-0.28470407323754404

Now that we’ve demonstrated how to declare and use constants in Scilab, let’s move on to learn more about the language.