Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2023.0.0 - English


type

returns the type of a Scilab object

Syntax

i = type(x)

Arguments

x

a Scilab object: a variable or valid expression.

i

integer code identiying the type of x.

Description

type(x) returns an integer which is the type of x, defined as following:

1
decimal or complex numbers
2
polynomials with real or complex coefficients
4
booleans
5
a sparse matrix.
6
a sparse boolean matrix.
7
Matlab sparse matrix
8
integers stored on 1 (int8), 2 (int16), 4 (int32), or 8 (int64) bytes.
9
graphic handles.
10
text objects.
13
a compiled function in Scilab code.
14
library of compiled Scilab functions.
15
a simple list.
16
a typed list (tlist).
17
a matrix-oriented typed list (mlist).
128
an identifier of a Xcos block, of a lufact()'s result, etc.
129
a size implicit polynomial used for indexing.
130
a built-in Scilab function, aka gateway (C, C++ or Fortran code).
0
An undefined element of a list (with a typeof void, such as in the function call foo(a,,b), or in list(%pi,,%i,,,%z)), or a null object of typeof listdelete returned by null().

Remarks

Some data may be stored in custom containers defined as typed lists of type 16 (tlist) or 17 (matrix-oriented typed mlist). This is also the case for embedded types like (rationals), structures (struct), state-space, interactive trees (uitree), etc, for which type(..) will return 16 or 17. One will use typeof to get more information about their actual (sub)type.

Type conversion in mixed operations:

When a binary operator (like the multiplication) or an n-ary iterated one (like the concatenation) is applied between two operands of distinct but compatible types, usually the type of one of both is implicitly converted, and the other operand sets the type of the result to its own type.

Examples with the concatenation : [%t, 3.124], [int8(5), 3.124], etc.

For the concatenation, addition, substraction, multiplication, division, and the power operation, the hierarchy between operands types is as follows (read "A < B": B imposes its type to A) :

  • boolean < (decimal number, complex encoded number)
  • (decimal number, complex-encoded number) < encoded integer.
  • polynomial (real | complex) < rational (real | complex)

Examples

// (Select some lines, right-click and choose "Execute.." to run the selection)
L = list(%pi,,"abc");
type(L(2))                  // undefined component of a list

type(42)                    // decimal numbers
type(%nan)
type(%inf)

type(1+%i)                  // complex numbers

s = sparse([1,2;4,5;3,10],[1,2,3]);
type(s)                     // sparse-encoded decimal or complex numbers

type(%t)                    // booleans

type(s>2)                   // sparse-encoded booleans

g = int8([1 -120 127 312]); // encoded integers
type(g)
type(1.23 * int8(4))

type(1-%z+%z^2)             // polynomials

type(gdf())                 // graphic handles

type("foo")                 // texts

deff('[x] = mymacro(y,z)',['a=3*y+1'; 'x=a*z+y']);
type(mymacro)               // Scilab functions

type(disp)                  // Built-in functions

l = list(1,["a" "b"]);      // simple lists
type(l)

e = tlist(["listtype","field1","field2"], [], []);
type(e)                     // Typed list

h = mlist(['V','name','value'],['a','b';'c' 'd'],[1 2; 3 4]);
type(h)                     // Typed matrix-oriented list

clear s, s.r = %pi          // structures
type(s)

c = {%t %pi %i %z "abc" s}  // cells
type(c)

r = [%z/(1-%z) (1-%z)/%z^2]
type(r)                     // rational fractions

See also

  • typeof — explicit type or overloading code of an object
  • inttype — type integers used in integer data types
  • isreal — check if a variable is stored as a complex matrix
  • brackets — Concatenation. Recipients of an assignment. Results of a function
  • overloading — display, functions and operators overloading capabilities
  • poly — Polynomial definition from given roots or coefficients, or characteristic to a square matrix.
  • rational — rational fractions
  • tlist — Scilab object and typed list definition.
  • mlist — Scilab object, matrix oriented typed list definition
  • null — deletes a list component or a field of a structure, Mlist, or Tlist

History

VersionDescription
6.0 The type 11 is removed. It was used for uncompiled Scilab functions.
Report an issue
<< strings types typename >>

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 Mar 27 11:52:41 GMT 2023