help format: (fr) added
[scilab.git] / scilab / modules / elementary_functions / help / en_US / floating_point / format.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) 2016 - Samuel GOUGEON
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  -->
15 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="format" xml:lang="en">
16     <refnamediv>
17         <refname>format</refname>
18         <refpurpose>set the default output format of decimal numbers</refpurpose>
19     </refnamediv>
20     <refsynopsisdiv>
21         <title>Syntax</title>
22         <synopsis>
23             format(mode)
24             format(width)
25             format(mode, width)
26             format(wm)
27             v = format()
28         </synopsis>
29     </refsynopsisdiv>
30     <refsection role="parameters">
31         <title>Arguments</title>
32         <variablelist>
33             <varlistentry>
34                 <term>mode</term>
35                 <listitem>
36                     <para>formatting mode:
37                         <itemizedlist>
38                           <listitem>1 or "v": <emphasis role="bold">v</emphasis>ariable adaptative
39                             formatting. Scilab chooses either the direct representation
40                             (e.g. -143.8757) or
41                             the exponential/engineering/scientific notation (e.g. -1.438E+02),
42                             in order to cope with each processed value as well as with the
43                             required width, with a maximal number of output digits.
44                           </listitem>
45                           <listitem>0 or "e": The <emphasis role="bold">e</emphasis>xponential
46                             /<emphasis role="bold">e</emphasis>ngineering notation is forced
47                             and used for all numbers.
48                           </listitem>
49                       </itemizedlist>
50                   </para>
51                 </listitem>
52             </varlistentry>
53             <varlistentry>
54                 <term>width</term>
55                 <listitem>
56                     <para>width of numbers = number of output characters used, all included: sign of
57                       the mantissa, its digits, decimal separator, exponent symbol, sign and digits
58                       of the exponent. (default width = 10)</para>
59                 </listitem>
60             </varlistentry>
61             <varlistentry>
62                 <term>wm</term>
63                 <listitem>
64                     <para>a vector to set new format </para>
65                     <para><literal>wm(1)</literal> is the width</para>
66                     <para><literal>wm(2)</literal> is the formatting mode: 0 for
67                       <literal>'e'</literal> and 1 for <literal>'v'</literal>
68                     </para>
69                 </listitem>
70             </varlistentry>
71             <varlistentry>
72                 <term>v</term>
73                 <listitem>
74                     <para>vector returning the current formatting parameters:
75                         <itemizedlist>
76                           <listitem><literal>v(1)</literal> is the formatting mode:
77                             0 for <literal>'e'</literal> and 1 for <literal>'v'</literal>
78                           </listitem>
79                           <listitem>
80                             <literal>v(2)</literal> is the width:
81                             Number of characters used to output each number.
82                           </listitem>
83                          </itemizedlist>
84                      </para>
85                  </listitem>
86             </varlistentry>
87         </variablelist>
88     </refsection>
89     <refsection role="description">
90         <title>Description</title>
91             <note>
92             For complex numbers, each real and imaginary decimal part is
93             output according to <literal>format(..)</literal>. The total width
94             of a complex number is therefore roughly twice greater (+ 1 character
95             for "i" symbol).
96             </note>
97             <note>Encoded integers are never output according to the "e"xponential mode, even when
98                 this formatting is the default mode set for decimal numbers. For them, the decimal
99                 separator "." is skipped. This allows to distinguish them from decimal integers
100                 that have a dot.
101             </note>
102             <note>For wide format(), digits that may be displayed beyond the
103                 relative accuracy <literal>%eps</literal> are set to 0.
104             </note>
105             <warning>The default decimal format set with
106                 <function>format(..)</function> is a global parameter:
107                 Wherever you set it, it then applies everywhere in Scilab and Xcos.
108             </warning>
109         <para>In the old Scilab versions, in "variable format" mode, vector
110             entries which are less than <literal>%eps</literal> times the maximum absolute value of the
111             entries were displayed as "0". It is no more the case, the clean function
112             can be used to set negligible entries to zeros.
113         </para>
114     </refsection>
115     <refsection role="examples">
116         <title>Examples</title>
117         <programlisting role="example"><![CDATA[
118 // format() is not taken into account for encoded integers
119 // -------------------------------------------------------
120 format("e",8)
121 int32(2.^grand(3,5,"uin",0,30))
122
123 // format() impacts console's output, disp(), string(), sci2exp(),...
124 // --------------------------------------------------------------
125 a = %pi; p = %pi + %z - %e*%z^2;
126 format("v",10);
127 a, p
128 disp(a,p)
129 string(a), string(p)
130 [sci2exp(a) sci2exp(p)]
131
132 format("e",15);
133 a, p
134 disp(a,p)
135 string(a), string(p)
136 [sci2exp(a) sci2exp(p)]
137 format("v",10); // reset
138
139 // format() set the width, not a fixed number of digits:
140 // ----------------------------------------------------
141 format("v",10)
142 %pi*1e-217, s = string(%pi*1e-217)
143 length(s) // the missing char is the implicit "+" sign
144
145 // This is useful to get aligned and fully informative display of matrices
146 [ -1.234 %pi*1e-10 %nan ; %e*1e137 -%inf 54312]
147
148 // Since Scilab 6.0, unrelevant digits displayed with wide format() are set to 0:
149 format(22)
150 %pi
151
152 // format() has a global impact
153 // ----------------------------
154 function myfun()
155     format("e",20)
156 endfunction
157 format("v", 10)
158 disp(%pi)
159 myfun()
160 // it remains everywhere, wherever it has been set:
161 disp(%pi)
162 format("v",10) // reset
163  ]]></programlisting>
164     </refsection>
165     <refsection role="see also">
166         <title>See Also</title>
167         <simplelist type="inline">
168             <member>
169                 <link linkend="number_properties">numbers properties</link>
170             </member>
171             <member>
172                 <link linkend="string">string</link>
173             </member>
174             <member>
175                 <link linkend="sci2exp">sci2exp</link>
176             </member>
177             <member>
178                 <link linkend="disp">disp</link>
179             </member>
180             <member>
181                 <link linkend="print">print</link>
182             </member>
183             <member>
184                 <link linkend="clean">clean</link>
185             </member>
186             <member>
187                 <link linkend="printf_conversion">C-like format</link>
188             </member>
189             <member>
190                 <link linkend="mprintf">mprintf</link>
191             </member>
192             <member>
193                 <link linkend="msprintf">msprintf</link>
194             </member>
195             <member>
196                 <link linkend="mfprintf">mfprintf</link>
197             </member>
198       </simplelist>
199     </refsection>
200     <refsection role="history">
201         <title>History</title>
202         <revhistory>
203             <revision>
204                 <revnumber>6.0</revnumber>
205                 <revdescription>For wide format(), digits that may be displayed
206                     beyond the relative accuracy %eps are now set to 0.
207                 </revdescription>
208             </revision>
209         </revhistory>
210     </refsection>
211 </refentry>