You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
7.2 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual describes how to install and use the GNU multiple precision
arithmetic library, version 6.1.0.
Copyright 1991, 1993-2015 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU Free Documentation License, Version 1.3 or any later
version published by the Free Software Foundation; with no Invariant Sections,
with the Front-Cover Texts being "A GNU Manual", and with the Back-Cover
Texts being "You have freedom to copy and modify this GNU Manual, like GNU
software". A copy of the license is included in
GNU Free Documentation License. -->
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
<head>
<title>I/O of Floats (GNU MP 6.1.0)</title>
<meta name="description" content="How to install and use the GNU multiple precision arithmetic library, version 6.1.0.">
<meta name="keywords" content="I/O of Floats (GNU MP 6.1.0)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="Floating_002dpoint-Functions.html#Floating_002dpoint-Functions" rel="up" title="Floating-point Functions">
<link href="Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions" rel="next" title="Miscellaneous Float Functions">
<link href="Float-Comparison.html#Float-Comparison" rel="prev" title="Float Comparison">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en">
<a name="I_002fO-of-Floats"></a>
<div class="header">
<p>
Next: <a href="Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions" accesskey="n" rel="next">Miscellaneous Float Functions</a>, Previous: <a href="Float-Comparison.html#Float-Comparison" accesskey="p" rel="prev">Float Comparison</a>, Up: <a href="Floating_002dpoint-Functions.html#Floating_002dpoint-Functions" accesskey="u" rel="up">Floating-point Functions</a> &nbsp; [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Input-and-Output-Functions-2"></a>
<h3 class="section">7.7 Input and Output Functions</h3>
<a name="index-Float-input-and-output-functions"></a>
<a name="index-Input-functions-2"></a>
<a name="index-Output-functions-2"></a>
<a name="index-I_002fO-functions-2"></a>
<p>Functions that perform input from a stdio stream, and functions that output to
a stdio stream, of <code>mpf</code> numbers. Passing a <code>NULL</code> pointer for a
<var>stream</var> argument to any of these functions will make them read from
<code>stdin</code> and write to <code>stdout</code>, respectively.
</p>
<p>When using any of these functions, it is a good idea to include <samp>stdio.h</samp>
before <samp>gmp.h</samp>, since that will allow <samp>gmp.h</samp> to define prototypes
for these functions.
</p>
<p>See also <a href="Formatted-Output.html#Formatted-Output">Formatted Output</a> and <a href="Formatted-Input.html#Formatted-Input">Formatted Input</a>.
</p>
<dl>
<dt><a name="index-mpf_005fout_005fstr"></a>Function: <em>size_t</em> <strong>mpf_out_str</strong> <em>(FILE *<var>stream</var>, int <var>base</var>, size_t <var>n_digits</var>, const mpf_t <var>op</var>)</em></dt>
<dd><p>Print <var>op</var> to <var>stream</var>, as a string of digits. Return the number of
bytes written, or if an error occurred, return 0.
</p>
<p>The mantissa is prefixed with an &lsquo;<samp>0.</samp>&rsquo; and is in the given <var>base</var>,
which may vary from 2 to 62 or from -2 to -36. An exponent is
then printed, separated by an &lsquo;<samp>e</samp>&rsquo;, or if the base is greater than 10 then
by an &lsquo;<samp>@</samp>&rsquo;. The exponent is always in decimal. The decimal point follows
the current locale, on systems providing <code>localeconv</code>.
</p>
<p>For <var>base</var> in the range 2..36, digits and lower-case letters are used; for
-2..-36, digits and upper-case letters are used; for 37..62,
digits, upper-case letters, and lower-case letters (in that significance order)
are used.
</p>
<p>Up to <var>n_digits</var> will be printed from the mantissa, except that no more
digits than are accurately representable by <var>op</var> will be printed.
<var>n_digits</var> can be 0 to select that accurate maximum.
</p></dd></dl>
<dl>
<dt><a name="index-mpf_005finp_005fstr"></a>Function: <em>size_t</em> <strong>mpf_inp_str</strong> <em>(mpf_t <var>rop</var>, FILE *<var>stream</var>, int <var>base</var>)</em></dt>
<dd><p>Read a string in base <var>base</var> from <var>stream</var>, and put the read float in
<var>rop</var>. The string is of the form &lsquo;<samp>M@N</samp>&rsquo; or, if the base is 10 or
less, alternatively &lsquo;<samp>MeN</samp>&rsquo;. &lsquo;<samp>M</samp>&rsquo; is the mantissa and &lsquo;<samp>N</samp>&rsquo; is the
exponent. The mantissa is always in the specified base. The exponent is
either in the specified base or, if <var>base</var> is negative, in decimal. The
decimal point expected is taken from the current locale, on systems providing
<code>localeconv</code>.
</p>
<p>The argument <var>base</var> may be in the ranges 2 to 36, or -36 to
-2. Negative values are used to specify that the exponent is in
decimal.
</p>
<p>Unlike the corresponding <code>mpz</code> function, the base will not be determined
from the leading characters of the string if <var>base</var> is 0. This is so that
numbers like &lsquo;<samp>0.23</samp>&rsquo; are not interpreted as octal.
</p>
<p>Return the number of bytes read, or if an error occurred, return 0.
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Miscellaneous-Float-Functions.html#Miscellaneous-Float-Functions" accesskey="n" rel="next">Miscellaneous Float Functions</a>, Previous: <a href="Float-Comparison.html#Float-Comparison" accesskey="p" rel="prev">Float Comparison</a>, Up: <a href="Floating_002dpoint-Functions.html#Floating_002dpoint-Functions" accesskey="u" rel="up">Floating-point Functions</a> &nbsp; [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>