Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - 日本語

Change language to:
English - Français - Português - Русский

Please note that the recommended version of Scilab is 2025.0.0. This page might be outdated.
See the recommended documentation of this function

Scilabヘルプ >> API Scilab > API integer functions

API integer functions

This page lists all the functions to manipulate Scilab native objects containing integers

scilabVar scilab_getIntegerPrecision( scilabEnv env, scilabVar var)

Return precision of an integer variable var.

int scilab_isInt8( scilabEnv env, scilabVar var)

int scilab_isInt16( scilabEnv env, scilabVar var)

int scilab_isInt32( scilabEnv env, scilabVar var)

int scilab_isInt64( scilabEnv env, scilabVar var)

int scilab_isUnsignedInt8( scilabEnv env, scilabVar var)

int scilab_isUnsignedInt16( scilabEnv env, scilabVar var)

int scilab_isUnsignedInt32( scilabEnv env, scilabVar var)

int scilab_isUnsignedInt64( scilabEnv env, scilabVar var)

Return 1 if variable val is an integer otherwise 0. Precision is specified in function name.

scilabVar scilab_createInteger8( scilabEnv env, char val)

scilabVar scilab_createInteger16( scilabEnv env, short val)

scilabVar scilab_createInteger32( scilabEnv env, int val)

scilabVar scilab_createInteger64( scilabEnv env, long long val)

scilabVar scilab_createUnsignedInteger8( scilabEnv env, unsigned char val)

scilabVar scilab_createUnsignedInteger16( scilabEnv env, unsigned short val)

scilabVar scilab_createUnsignedInteger32( scilabEnv env, unsigned int val)

scilabVar scilab_createUnsignedInteger64( scilabEnv env, unsigned long long val)

Create a scalar integer from val. Precision is specified in function name.

scilabVar scilab_createIntegerMatrix( scilabEnv env, int prec, int dim, const int* dims)

Create an integer matrix with dim dimensions (dims[0], dims[1], ..., dims[dim-1]).

The prec parameter specifies the integer precision :

SCI_INT8: integer 8-bits
SCI_INT16: Integer 16-bits
SCI_INT32: Integer 32-bits
SCI_INT64: Integer 64-bits
SCI_UINT8: Unsigned integer 8-bits
SCI_UINT16: Unsigned integer 16-bits
SCI_UINT32: Unsigned integer 32-bits
SCI_UINT64: Unsigned integer 64-bits

scilabVar scilab_createInteger8Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createInteger16Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createInteger32Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createInteger64Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createUnsignedInteger8Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createUnsignedInteger16Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createUnsignedInteger32Matrix( scilabEnv env, int prec, int dim, const int* dims)

scilabVar scilab_createUnsignedInteger64Matrix( scilabEnv env, int prec, int dim, const int* dims)

Create an integer matrix with dim dimensions (dims[0], dims[1], ..., dims[dim-1]). Precision is specified in function name.

scilabVar scilab_createIntegerMatrix2d( scilabEnv env, int prec, int row, int col)

Create an integer matrix with 2 dimensions (row, col).

prec parameter give precision.

scilabVar scilab_createInteger8Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createInteger16Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createInteger32Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createInteger64Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createUnsignedInteger8Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createUnsignedInteger16Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createUnsignedInteger32Matrix2d( scilabEnv env, int row, int col)

scilabVar scilab_createUnsignedInteger64Matrix2d( scilabEnv env, int row, int col)

Create an integer matrix with 2 dimensions (row, col). Precision is specified in function name.

scilabStatus scilab_getInteger8( scilabEnv env, scilabVar var, char* vals)

scilabStatus scilab_getInteger16( scilabEnv env, scilabVar var, short* vals)

scilabStatus scilab_getInteger32( scilabEnv env, scilabVar var, int* vals)

scilabStatus scilab_getInteger64( scilabEnv env, scilabVar var, long long* vals)

scilabStatus scilab_getUnsignedInteger8( scilabEnv env, scilabVar var, unsigned char* vals)

scilabStatus scilab_getUnsignedInteger16( scilabEnv env, scilabVar var, unsigned short* vals)

scilabStatus scilab_getUnsignedInteger32( scilabEnv env, scilabVar var, unsigned int* vals)

scilabStatus scilab_getUnsignedInteger64( scilabEnv env, scilabVar var, unsigned long long* vals)

Get integer value from an scalar integer variable. Precision is specified in function name.

precision of output must match with precision of var.

scilabStatus scilab_getIntegerArray( scilabEnv env, scilabVar var, void** vals)

scilabStatus scilab_getInteger8Array( scilabEnv env, scilabVar var, char** vals)

scilabStatus scilab_getInteger16Array( scilabEnv env, scilabVar var, short** vals)

scilabStatus scilab_getInteger32Array( scilabEnv env, scilabVar var, int** vals)

scilabStatus scilab_getInteger64Array( scilabEnv env, scilabVar var, long long** vals)

scilabStatus scilab_getUnsignedInteger8Array( scilabEnv env, scilabVar var, unsigned char** vals)

scilabStatus scilab_getUnsignedInteger16Array( scilabEnv env, scilabVar var, unsigned short** vals)

scilabStatus scilab_getUnsignedInteger32Array( scilabEnv env, scilabVar var, unsigned int** vals)

scilabStatus scilab_getUnsignedInteger64Array( scilabEnv env, scilabVar var, unsigned long long** vals)

Get pointer on internal array of integer of var.

scilabStatus scilab_setIntegerArray( scilabEnv env, scilabVar var, const void* vals);

scilabStatus scilab_setInteger8Array( scilabEnv env, scilabVar var, const char* vals);

scilabStatus scilab_setInteger16Array( scilabEnv env, scilabVar var, const short* vals);

scilabStatus scilab_setInteger32Array( scilabEnv env, scilabVar var, const int* vals);

scilabStatus scilab_setInteger64Array( scilabEnv env, scilabVar var, const long long* vals);

scilabStatus scilab_setUnsignedInteger8Array( scilabEnv env, scilabVar var, const unsigned char* vals);

scilabStatus scilab_setUnsignedInteger16Array( scilabEnv env, scilabVar var, const unsigned short* vals);

scilabStatus scilab_setUnsignedInteger32Array( scilabEnv env, scilabVar var, const unsigned int* vals);

scilabStatus scilab_setUnsignedInteger64Array( scilabEnv env, scilabVar var, const unsigned long long* vals);

Set values of integer variable var.

Examples

#include "api_scilab.h"
#include "Scierror.h"
#include "localization.h"
#include "sciprint.h"
#include "sci_malloc.h"

const char fname[] = "int_test";

int sci_int_test(scilabEnv env, int nin, scilabVar* in, int nopt, scilabOpt opt, int nout, scilabVar* out)
{
    int i = 0;
    int inr1 = 0;
    int inc1 = 0;
    int size1 = 0;
    int* in1 = NULL;

    int in2 = 0;

    int* out1 = NULL;

    int* out2dims = NULL;
    int* out2 = NULL;

    int out3 = 0;

    if (nin != 2)
    {
        Scierror(999, _("%s: Wrong number of input arguments: %d expected.\n"), fname, 2);
        return SCILAB_ERROR;
    }

    if (nout != 3)
    {
        Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname, 3);
        return SCILAB_ERROR;
    }

    //in[0] : matrix 2d of int32
    if (scilab_isInt32(env, in[0]) == 0 || scilab_isMatrix(env, in[0]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A int32 matrix expected.\n"), fname, 1);
        return SCILAB_ERROR;
    }

    size1 = scilab_getDim2d(env, in[0], &inr1, &inc1);
    scilab_getInteger32Array(env, in[0], &in1);

    //in[1] : int
    if (scilab_isInt32(env, in[1]) == 0 || scilab_isScalar(env, in[1]) == 0)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A int expected.\n"), fname, 2);
        return SCILAB_ERROR;
    }

    scilab_getInteger32(env, in[1], &in2);

    //out1 : matrix 2d of int with same size of in[0]
    out[0] = scilab_createIntegerMatrix2d32(env, inr1, inc1);
    scilab_getInteger32Array(env, out[0], &out1);

    for (i = 0; i < size1; ++i)
    {
        out1[i] = in1[i] * 10;
    }

    //out2 : 3d matrix of int
    out2dims = (int*)MALLOC(3 * sizeof(int));
    out2dims[0] = inr1;
    out2dims[1] = inc1;
    out2dims[2] = 2;

    out[1] = scilab_createIntegerMatrix32(env, 3, out2dims, 0);
    scilab_getInteger32Array(env, out[1], &out2);

    for (i = 0; i < size1; ++i)
    {
        out2[i] = in1[i] * 10;
        out2[i + size1] = in1[i] * 100;
    }

    //out3 : int
    out[2] = scilab_createInteger32(env, in2 * 1000);
    return SCILAB_OK;
}

Scilab test script

mkdir(pathconvert(TMPDIR+"/api_c/"));
cd(pathconvert(TMPDIR+"/api_c/"));
copyfile(SCI+"/modules/api_scilab/tests/unit_tests/api_c/int_test.c",pathconvert(TMPDIR+"/api_c/int_test.c",%F));

ilib_build("libint",["int_test","sci_int_test", "csci6"],"int_test.c",[],"","","");
exec("loader.sce");

in1 = int32(rand(3,4) *1000);
in2 = int32(rand() * 1000);

[out1, out2, out3] = int_test(in1, in2);

assert_checkequal(out1, in1 * 10);
ref(:,:, 1) = in1 * 10;
ref(:,:, 2) = in1 * 100;
assert_checkequal(out2, ref);
assert_checkequal(out3, in2 * 1000);
disp("OK");
Report an issue
<< API boolean functions API Scilab API list-type functions >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jan 03 14:38:07 CET 2022