Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Please login or create an account
Change language to: English - Português - Русский - 日本語

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

Aide de Scilab >> API Scilab > Low level functions > Integer Precision (Scilab gateway)

Integer Precision (Scilab gateway)

How to get precision of an integer matrix.

Calling Sequence

SciErr getMatrixOfIntegerPrecision(void* _pvCtx, int* _piAddress, int* _piPrecision)
SciErr getNamedMatrixOfIntegerPrecision(void* _pvCtx, const char* _pstName, int* _piPrecision)

Arguments

_pvCtx

Scilab environment pointer, pass in "pvApiCtx" provided by api_scilab.h

_piAddress

Address of the variable.

_pstName

Name of the variable for "named" functions.

_piPrecision

Return precision of an integer variable. If value is greater then 10 then the variable is unsigned.

SciErr

Error structure where is stored errors messages history and first error number.

Description

This help describes how to get precision of an integer matrix.

Gateway Source

#include "api_scilab.h"
SciErr printf_info(int _iVar);

int common_function(char *fname,unsigned long fname_len)
{
	SciErr sciErr;
	int i;
	int *piAddr1    = NULL;
	int iBool       = 0;

	for(i = 0 ; i < nbInputArgument(pvApiCtx) ; i++)
	{
		sciErr = printf_info(i + 1);
		if(sciErr.iErr)
		{
			printError(&sciErr, 0);
			break;
		}
		sciprint("\n\n");
	}

	//1 for true, 0 for false
	iBool = sciErr.iErr == 0 ? 1 : 0;

	sciErr = createMatrixOfBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 1, &iBool);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	//assign allocated variables to Lhs position
	AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
	return 0;
}

SciErr printf_info(int _iVar)
{
	SciErr sciErr;
	int* piAddr     = NULL;
	int iType       = 0;

	sciErr = getVarAddressFromPosition(pvApiCtx, _iVar, &piAddr);
	if(sciErr.iErr)
	{
		return sciErr;
	}

	sciprint("Variable %d information:\n", _iVar);

	sciErr = getVarType(pvApiCtx, piAddr, &iType);
	if(sciErr.iErr)
	{
		return sciErr;
	}

	sciprint("\tType: ");
	if(iType == sci_ints)
	{
		char pstSigned[]    = "signed";
		char pstUnsigned[]  = "unsigned";
		char* pstSign       = pstSigned;
		int iPrec           = 0;

		sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr, &iPrec);
		if(sciErr.iErr)
		{
			return sciErr;
		}

		if(iPrec > 10)
		{
			pstSign = pstUnsigned;
		}

		sciprint("%s integer %d bits\n", pstSign, (iPrec % 10) * 8);
    }
	else
	{
		sciprint("Not manage by this function\n");
		return sciErr;
    }
	
	return sciErr;
}

Scilab test script

l1 = [1,2*%i,3;%i,2,3*%i];
l2 = ["may","the";"puffin","be";"with","you"];
l3 = int8([1,2,3]);
l4 = uint16([1000,2000,3000]);
l5 = list(l1,l2,l3);
l = list(l1,l2,l3,l4,l5);
common_function(l(1:$))
Scilab Enterprises
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu Oct 02 13:54:44 CEST 2014