1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
<html><head><title>XLISP *float-format*</title>
<link rel="stylesheet" type="text/css" href="reference.css">
</head>
<body>
<a href="../start.htm">Nyquist / XLISP 2.0</a> -
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>
<hr>
<h1>*float-format*</h1>
<hr>
<p><table cellpadding="0" cellspacing="0" style="margin-left:10px"><tbody>
<tr valign="top">
<td><nobr>Type:</nobr></td>
<td><nobr> - </nobr></td>
<td width="100%"><nobr>system variable</nobr></td>
</tr>
<tr valign="top">
<td><nobr>Source:</nobr></td>
<td><nobr> - </nobr></td>
<td width="100%"><nobr>xlprin.c</nobr></td>
</tr>
</tbody></table></p>
<h2>Syntax</h2>
<dl>
<dt> *float-format*</dt>
<dd>returns - the print format for <nobr>floating-point</nobr> numbers</dd>
</dl>
<h2>Description</h2>
<p> *float-format* is a system variable that allows a user to specify how
floating point numbers are to be printed by XLISP. The value of
*float-format* should be set to one of the string expressions
"%e", "%f" or "%g". These format strings are
similar to C-language floating point specifications:</p>
<p><table cellpadding="0" cellspacing="0"><tbody>
<tr valign="top">
<td><nobr><code> "%e"</code></nobr></td>
<td><nobr> -<code> </code></nobr></td>
<td width="100%">exponential. The number is converted to decimal notation
of the form:
<pre class="example">
[-]<font color="#0000CC"><i>m</i></font>.<font color="#0000CC"><i>nnnnnn</i></font>E[+-]<font color="#0000CC"><i>xx</i></font>
</pre>
There is one leading digit. There are 6 digits after the decimal
point.</td>
</tr>
<tr>
<td><nobr><font size="-2"> </font></nobr></td>
</tr>
<tr valign="top">
<td><nobr><code> "%f"</code></nobr></td>
<td><nobr> -<code> </code></nobr></td>
<td width="100%">decimal. The number is converted to decimal notation of
the form:
<pre class="example">
[-]<font color="#0000CC"><i>mmmmmm</i></font>.<font color="#0000CC"><i>nnnnnn</i></font>
</pre>
There are as many digits before the decimal point as necessary. There
are 6 digits after the decimal point.</td>
</tr>
<tr>
<td><nobr><font size="-2"> </font></nobr></td>
</tr>
<tr valign="top">
<td><nobr><code> "%g"</code></nobr></td>
<td><nobr> -<code> </code></nobr></td>
<td width="100%">shortest. The number is converted to either the form of
"%e" or "%f", whichever produces the shortest output
string. Non-significant zeroes are not printed.</td>
</tr>
</tbody></table></p>
<p> The default value for *float-format* is the string "%g".</p>
<p>There are several additional flags and options available:</p>
<p><table cellpadding="0" cellspacing="0"><tbody>
<tr>
<td><nobr><code> </code></nobr></td>
<td><nobr><code> +</code></nobr></td>
<td><nobr> <code> </code>-<code> </code></nobr></td>
<td width="100%"><nobr>always print the sign</nobr></td>
</tr>
<tr>
<td><nobr><code> </code></nobr></td>
<td><nobr><code><i>space</i></code></nobr></td>
<td><nobr> <code> </code>-<code> </code></nobr></td>
<td width="100%"><nobr>print a space instead of a + sign</nobr></td>
</tr>
<tr>
<td><nobr><code> </code></nobr></td>
<td><nobr><code> #</code></nobr></td>
<td><nobr> <code> </code>-<code> </code></nobr></td>
<td width="100%"><nobr>always print the dot, do not remove zeros after the dot</nobr></td>
</tr>
<tr>
<td><nobr><code> </code></nobr></td>
<td><nobr><code> .<i>n</i></code></nobr></td>
<td><nobr> <code> </code>-<code> </code></nobr></td>
<td width="100%"><nobr>number of digits after the dot</nobr></td>
</tr>
</tbody></table></p>
<p>The flags and options must be written between the "%" and the
formatting letter, as shown in the examples below.</p>
<h2>Examples</h2>
<pre class="example">
(setq *float-format* "%e") <font color="#008844">; exponential notation</font>
(print 1.0) => 1.000000e+00
(print -9e99) => -9.000000e+99
(setq *float-format* "%f") <font color="#008844">; decimal notation</font>
(print 1.0) => 1.000000
(print 1.0e4) => 10000.000000
(print -999.99e-99) => -0.000000</font>
(setq *float-format* "%g") <font color="#008844">; shortest notation</font>
(print 1.0) => 1
(print 1.0e7) => 1e+07
(print -999.999e99) => -9.99999e+101
(setq *float-format* "%+g") <font color="#008844">; always print the sign</font>
(print 1.1) => +1.1
(print -1.1) => -1.1
(setq *float-format* "% g") <font color="#008844">; print a space instead of the + sign</font>
(print 1.1) => 1.1
(print -1.1) => -1.1
(setq *float-format* "%#.10g") <font color="#008844">; ten digits after the dot</font>
(print 1.0) => 1.000000000
(print 1.0e7) => 10000000.00
(print -999.9999999e99) => -9.999999999e+101
(setq *float-format* "%+#.10g") <font color="#008844">; ten digits after the dot plus sign</font>
(print 1.2345) => +1.234500000
(print -1.2345) => -1.234500000
(setq *float-format* "%%") <font color="#008844">; bad format</font>
(print 1.0) => %%
(setq *float-format* "%g") <font color="#008844">; reset to shortest notation</font>
</pre>
<p><b>Note:</b> The string in the <nobr>*float-format*</nobr> variable is
the format specifier for the the underlying 'sprintf'
<nobr>C-function</nobr>.</p>
<p><nobr> <a href="#top">Back to Top</nobr></a></p>
<hr>
<a href="../start.htm">Nyquist / XLISP 2.0</a> -
<a href="../manual/contents.htm">Contents</a> |
<a href="../tutorials/tutorials.htm">Tutorials</a> |
<a href="../examples/examples.htm">Examples</a> |
<a href="reference-index.htm">Reference</a>
</body></html>
|