* Bug 15431 fixed [doc]: empty [] better documented
[scilab.git] / scilab / modules / integer / help / en_US / iconvert.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) INRIA -
5  * Copyright (C) 2018 - Samuel GOUGEON
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15  *
16  -->
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18         xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
19         xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab"
20         xml:lang="en" xml:id="iconvert">
21     <refnamediv>
22         <refname>iconvert</refname>
23         <refpurpose> conversion to 1 to 8 byte integer representation</refpurpose>
24     </refnamediv>
25     <refsynopsisdiv>
26         <title>Syntax</title>
27         <synopsis>y = iconvert(X, itype)</synopsis>
28     </refsynopsisdiv>
29     <refsection>
30         <title>Arguments</title>
31         <variablelist>
32             <varlistentry>
33                 <term>X</term>
34                 <listitem>
35                     <para>
36                       a matrix of decimal numbers, encoded integers, or booleans.
37                       Complex numbers are not supported.
38                     </para>
39                 </listitem>
40             </varlistentry>
41             <varlistentry>
42                 <term>itype</term>
43                 <listitem>
44                     <para>an integer: conversion code</para>
45                 </listitem>
46             </varlistentry>
47             <varlistentry>
48                 <term>y</term>
49                 <listitem>
50                     <para>
51                         matrix of integers encoded on 1, 2, 4 or 8 bytes, with the sizes of
52                         <varname>X</varname> : <literal>y(i)</literal> is <literal>X(i)</literal>
53                         converted into the chosen encoding.
54                     </para>
55                 </listitem>
56             </varlistentry>
57         </variablelist>
58     </refsection>
59     <refsection>
60         <title>Description</title>
61         <para>
62             The <function>iconvert</function> function converts and stores data to 1, 2, 4 or
63             8 bytes integers. Please refer to the <link linkend="int8">int8()</link> page for a
64             detailled description.
65         </para>
66         <para>
67             <table>
68                 <tr><th>itype</th><th>y typeof</th> <th>range</th></tr>
69                 <tr><th>0</th>  <td>(reals)</td>    <td></td></tr>
70                 <tr><th>1</th>  <td>int8</td>   <td>[-128, 127]</td></tr>
71                 <tr><th>2</th>  <td>int16</td>  <td>[-32768, 32767]</td></tr>
72                 <tr><th>4</th>  <td>int32</td>  <td>[-2147483648, 2147483647]</td></tr>
73                 <tr><th>8</th>  <td>int64</td>  <td>[-9223372036854775808, 9223372036854775807]</td></tr>
74                 <tr><th>11</th> <td>uint8</td>  <td>[0, 255]</td></tr>
75                 <tr><th>12</th> <td>uint16</td> <td>[0, 65535]</td></tr>
76                 <tr><th>14</th> <td>uint32</td> <td>[0, 4294967295]</td></tr>
77                 <tr><th>18</th> <td>uint64</td> <td>[0, 18446744073709551615]</td></tr>
78             </table>
79         </para>
80         <warning>
81             Converting <literal>[]</literal> always keeps it as is, of type 1 == inttype 0
82            (decimal type).
83         </warning>
84     </refsection>
85     <refsection>
86         <title>Examples</title>
87         <programlisting role="example"><![CDATA[
88 b=int32([1 -120 127 312])
89 y=iconvert(b,1)
90
91 typeof(b)
92 typeof(y)
93  ]]></programlisting>
94     <para/>
95     <programlisting role="example"><![CDATA[
96 iconvert([-3.6 -2.5 -1.2 1.2 2.5 3.6], 1)
97 iconvert([-%inf %inf %nan], 1)
98 iconvert([-%inf %inf %nan], 11)
99 iconvert(-1, 11)
100 iconvert(-1, 12)
101 iconvert(-1, 14)
102 iconvert(-1, 18)
103  ]]></programlisting>
104     <screen><![CDATA[
105 --> iconvert([-3.6 -2.5 -1.2 1.2 2.5 3.6], 1)
106  ans  =
107  -3 -2 -1  1  2  3
108
109 --> iconvert([-%inf %inf %nan], 1)
110  ans  =
111  -128  127  0
112
113 --> iconvert([-%inf %inf %nan], 11)
114  ans  =
115   0  255  0
116
117 --> iconvert(-1, 11)
118  ans  =
119   255
120
121 --> iconvert(-1, 12)
122  ans  =
123   65535
124
125 --> iconvert(-1, 14)
126  ans  =
127   4294967295
128
129 --> iconvert(-1, 18)
130  ans  =
131   18446744073709551615
132 ]]></screen>
133     </refsection>
134     <refsection role="see also">
135         <title>See also</title>
136         <simplelist type="inline">
137             <member>
138                 <link linkend="int8">int8</link>
139             </member>
140             <member>
141                 <link linkend="inttype">inttype</link>
142             </member>
143             <member>
144                 <link linkend="double">double</link>
145             </member>
146             <member>
147                 <link linkend="dec2bin">dec2bin</link>
148             </member>
149             <member>
150                 <link linkend="dec2base">dec2base</link>
151             </member>
152         </simplelist>
153     </refsection>
154     <refsection role="history">
155         <title>History</title>
156         <revhistory>
157             <revision>
158                 <revnumber>6.0</revnumber>
159                 <revdescription>
160                     <itemizedlist>
161                         <listitem>
162                             Support to int64 and uint64 encodings added.
163                         </listitem>
164                         <listitem>
165                             <table>
166                                 <tr><th>This</th>              <th>is now</th>     <th>instead of</th></tr>
167                                 <tr><td>iconvert([-%inf,%inf], 1)</td><td>[-128, 127]</td><td>[0, 0]</td></tr>
168                                 <tr><td>iconvert([-%inf,%inf], 2)</td><td>[-32768, 32767]</td><td>[0, 0]</td></tr>
169                                 <tr><td>iconvert(%inf, 4)</td>  <td>2147483647</td> <td>-2147483648</td></tr>
170                                 <tr><td>iconvert(%inf, 11)</td> <td>255</td>        <td>0</td></tr>
171                                 <tr><td>iconvert(%inf, 12)</td> <td>65535</td>      <td>0</td></tr>
172                                 <tr><td>iconvert(%inf, 14)</td> <td>4294967295</td> <td>0</td></tr>
173                             </table>
174                         </listitem>
175                     </itemizedlist>
176                 </revdescription>
177             </revision>
178         </revhistory>
179     </refsection>
180 </refentry>