Scilab2C Data Annotations — Scilab to C Converter : Data Annotations How To
Data annotations are used to define the size, type and precisions of variables and numbers used in the Scilab code.
By default Sci2C assumes the double precision, which is the default precision used by the Scilab language. Actually the whole Scilab software only works with double precision. Pay attention that the computation done in Scilab and the C code generated with single precision can differ.
It is possible to force a default precision for each source file, by using a dedicated annotation that must be inserted after the function annotation section (Cf. Function Annotation.):
//SCI2C: DEFAULT_PRECISION= precision
This annotation specifies the default precision for all the data used in the function body. Allowed settings for precision are:
//SCI2C: DEFAULT_PRECISION= FLOAT
//SCI2C: DEFAULT_PRECISION= DOUBLE
If not otherwise specified, the precision of the data will be float single and float double, respectively.
It is also possible to force some variable having a certain type using functions :
//SCI2C: DEFAULT_PRECISION= FLOAT y = 10;This will generate a C code with the
y
variable declared as a scalar, real, float.
x = -10.3; y = zeros(10,3); z = double(-10.3);Assuming
//SCI2C: DEFAULT_PRECISION
is not present, the default precision will be DOUBLE
This will generate a C code with
x
as scalar real double.
y
as 10 by 3 matrix of real double filled with zeros.
z
as scalar real double. In this case the double specifier is redundant.
//SCI2C: DEFAULT_PRECISION= FLOAT x = -10.3; y = float(zeros(10,3)); z = double(-10.3);This will generate a C code with
x
as scalar real float.
y
as 10 by 3 matrix of real float filled with zeros. In this case the float specifier is redundant.
z
as scalar real double.
//SCI2C: DEFAULT_PRECISION= FLOAT x = double(3); y = double(4); z = x + y;This will generate a C code with
x
as scalar real double.
y
as scalar real double.
z
as scalar real double. According to the behaviour of +
operator and due to the fact that x
and y
are both in double precision, Scilab2C will set z
with double precision.