/usr/share/doc/libmpfr-doc/mpfr.html/Assignment-Functions.html is in libmpfr-doc 4.0.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This manual documents how to install and use the Multiple Precision
Floating-Point Reliable Library, version 4.0.1.
Copyright 1991, 1993-2018 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.2 or any later
version published by the Free Software Foundation; with no Invariant Sections,
with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the
license is included in GNU Free Documentation License. -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Assignment Functions (GNU MPFR 4.0.1)</title>
<meta name="description" content="How to install and use GNU MPFR, a library for reliable multiple precision
floating-point arithmetic, version 4.0.1.">
<meta name="keywords" content="Assignment Functions (GNU MPFR 4.0.1)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="MPFR-Interface.html#MPFR-Interface" rel="up" title="MPFR Interface">
<link href="Combined-Initialization-and-Assignment-Functions.html#Combined-Initialization-and-Assignment-Functions" rel="next" title="Combined Initialization and Assignment Functions">
<link href="Initialization-Functions.html#Initialization-Functions" rel="prev" title="Initialization Functions">
<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="Assignment-Functions"></a>
<div class="header">
<p>
Next: <a href="Combined-Initialization-and-Assignment-Functions.html#Combined-Initialization-and-Assignment-Functions" accesskey="n" rel="next">Combined Initialization and Assignment Functions</a>, Previous: <a href="Initialization-Functions.html#Initialization-Functions" accesskey="p" rel="prev">Initialization Functions</a>, Up: <a href="MPFR-Interface.html#MPFR-Interface" accesskey="u" rel="up">MPFR Interface</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="index-Assignment-functions"></a>
<a name="Assignment-Functions-1"></a>
<h3 class="section">5.2 Assignment Functions</h3>
<p>These functions assign new values to already initialized floats
(see <a href="Initialization-Functions.html#Initialization-Functions">Initialization Functions</a>).
</p>
<dl>
<dt><a name="index-mpfr_005fset"></a>Function: <em>int</em> <strong>mpfr_set</strong> <em>(mpfr_t <var>rop</var>, mpfr_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fui"></a>Function: <em>int</em> <strong>mpfr_set_ui</strong> <em>(mpfr_t <var>rop</var>, unsigned long int <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fsi"></a>Function: <em>int</em> <strong>mpfr_set_si</strong> <em>(mpfr_t <var>rop</var>, long int <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fuj"></a>Function: <em>int</em> <strong>mpfr_set_uj</strong> <em>(mpfr_t <var>rop</var>, uintmax_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fsj"></a>Function: <em>int</em> <strong>mpfr_set_sj</strong> <em>(mpfr_t <var>rop</var>, intmax_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fflt"></a>Function: <em>int</em> <strong>mpfr_set_flt</strong> <em>(mpfr_t <var>rop</var>, float <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fd"></a>Function: <em>int</em> <strong>mpfr_set_d</strong> <em>(mpfr_t <var>rop</var>, double <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fld"></a>Function: <em>int</em> <strong>mpfr_set_ld</strong> <em>(mpfr_t <var>rop</var>, long double <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005ffloat128"></a>Function: <em>int</em> <strong>mpfr_set_float128</strong> <em>(mpfr_t <var>rop</var>, __float128 <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fdecimal64"></a>Function: <em>int</em> <strong>mpfr_set_decimal64</strong> <em>(mpfr_t <var>rop</var>, _Decimal64 <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fz"></a>Function: <em>int</em> <strong>mpfr_set_z</strong> <em>(mpfr_t <var>rop</var>, mpz_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fq"></a>Function: <em>int</em> <strong>mpfr_set_q</strong> <em>(mpfr_t <var>rop</var>, mpq_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005ff"></a>Function: <em>int</em> <strong>mpfr_set_f</strong> <em>(mpfr_t <var>rop</var>, mpf_t <var>op</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dd><p>Set the value of <var>rop</var> from <var>op</var>, rounded
toward the given direction <var>rnd</var>.
Note that the input 0 is converted to +0 by <code>mpfr_set_ui</code>,
<code>mpfr_set_si</code>, <code>mpfr_set_uj</code>, <code>mpfr_set_sj</code>,
The <code>mpfr_set_float128</code> function is built only with the configure
option ‘<samp>--enable-float128</samp>’, which requires the compiler or
system provides the ‘<samp>__float128</samp>’ data type
(GCC 4.3 or later supports this data type);
to use <code>mpfr_set_float128</code>, one should define the macro
<code>MPFR_WANT_FLOAT128</code> before including <samp>mpfr.h</samp>.
<code>mpfr_set_z</code>, <code>mpfr_set_q</code> and
<code>mpfr_set_f</code>, regardless of the rounding mode.
If the system does not support the IEEE 754 standard,
<code>mpfr_set_flt</code>, <code>mpfr_set_d</code>, <code>mpfr_set_ld</code> and
<code>mpfr_set_decimal64</code> might not preserve the signed zeros.
The <code>mpfr_set_decimal64</code> function is built only with the configure
option ‘<samp>--enable-decimal-float</samp>’, and when the compiler or
system provides the ‘<samp>_Decimal64</samp>’ data type
(recent versions of GCC support this data type);
to use <code>mpfr_set_decimal64</code>, one should define the macro
<code>MPFR_WANT_DECIMAL_FLOATS</code> before including <samp>mpfr.h</samp>.
<code>mpfr_set_q</code> might fail if the numerator (or the
denominator) can not be represented as a <code>mpfr_t</code>.
</p>
<p>For <code>mpfr_set</code>, the sign of a NaN is propagated in order to mimic the
IEEE 754 <code>copy</code> operation. But contrary to IEEE 754, the NaN flag is
set as usual.
</p>
<p>Note: If you want to store a floating-point constant to a <code>mpfr_t</code>,
you should use <code>mpfr_set_str</code> (or one of the MPFR constant functions,
such as <code>mpfr_const_pi</code> for <em>Pi</em>) instead of
<code>mpfr_set_flt</code>, <code>mpfr_set_d</code>,
<code>mpfr_set_ld</code> or <code>mpfr_set_decimal64</code>.
Otherwise the floating-point constant will be first
converted into a reduced-precision (e.g., 53-bit) binary
(or decimal, for <code>mpfr_set_decimal64</code>) number before
MPFR can work with it.
</p></dd></dl>
<dl>
<dt><a name="index-mpfr_005fset_005fui_005f2exp"></a>Function: <em>int</em> <strong>mpfr_set_ui_2exp</strong> <em>(mpfr_t <var>rop</var>, unsigned long int <var>op</var>, mpfr_exp_t <var>e</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fsi_005f2exp"></a>Function: <em>int</em> <strong>mpfr_set_si_2exp</strong> <em>(mpfr_t <var>rop</var>, long int <var>op</var>, mpfr_exp_t <var>e</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fuj_005f2exp"></a>Function: <em>int</em> <strong>mpfr_set_uj_2exp</strong> <em>(mpfr_t <var>rop</var>, uintmax_t <var>op</var>, intmax_t <var>e</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fsj_005f2exp"></a>Function: <em>int</em> <strong>mpfr_set_sj_2exp</strong> <em>(mpfr_t <var>rop</var>, intmax_t <var>op</var>, intmax_t <var>e</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fz_005f2exp"></a>Function: <em>int</em> <strong>mpfr_set_z_2exp</strong> <em>(mpfr_t <var>rop</var>, mpz_t <var>op</var>, mpfr_exp_t <var>e</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dd><p>Set the value of <var>rop</var> from <em><var>op</var> multiplied by
two to the power <var>e</var></em>, rounded toward the given direction <var>rnd</var>.
Note that the input 0 is converted to +0.
</p></dd></dl>
<dl>
<dt><a name="index-mpfr_005fset_005fstr"></a>Function: <em>int</em> <strong>mpfr_set_str</strong> <em>(mpfr_t <var>rop</var>, const char *<var>s</var>, int <var>base</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dd><p>Set <var>rop</var> to the value of the string <var>s</var> in base <var>base</var>,
rounded in the direction <var>rnd</var>.
See the documentation of <code>mpfr_strtofr</code> for a detailed description
of the valid string formats.
Contrary to <code>mpfr_strtofr</code>, <code>mpfr_set_str</code> requires the
<em>whole</em> string to represent a valid floating-point number.
</p>
<p>The meaning of the return value differs from other MPFR functions:
it is 0 if the entire string up to the final null character
is a valid number in base <var>base</var>; otherwise it is −1, and
<var>rop</var> may have changed (users interested in the <a href="Rounding-Modes.html#ternary-value">ternary value</a>
should use <code>mpfr_strtofr</code> instead).
</p>
<p>Note: it is preferable to use <code>mpfr_strtofr</code> if one wants to distinguish
between an infinite <var>rop</var> value coming from an infinite <var>s</var> or from
an overflow.
</p></dd></dl>
<dl>
<dt><a name="index-mpfr_005fstrtofr"></a>Function: <em>int</em> <strong>mpfr_strtofr</strong> <em>(mpfr_t <var>rop</var>, const char *<var>nptr</var>, char **<var>endptr</var>, int <var>base</var>, mpfr_rnd_t <var>rnd</var>)</em></dt>
<dd><p>Read a floating-point number from a string <var>nptr</var> in base <var>base</var>,
rounded in the direction <var>rnd</var>; <var>base</var> must be either 0 (to
detect the base, as described below) or a number from 2 to 62 (otherwise
the behavior is undefined). If <var>nptr</var> starts with valid data, the
result is stored in <var>rop</var> and <code>*<var>endptr</var></code> points to the
character just after the valid data (if <var>endptr</var> is not a null pointer);
otherwise <var>rop</var> is set to zero (for consistency with <code>strtod</code>)
and the value of <var>nptr</var> is stored
in the location referenced by <var>endptr</var> (if <var>endptr</var> is not a null
pointer). The usual ternary value is returned.
</p>
<p>Parsing follows the standard C <code>strtod</code> function with some extensions.
After optional leading whitespace, one has a subject sequence consisting of an
optional sign (‘<samp>+</samp>’ or ‘<samp>-</samp>’), and either numeric data or special
data. The subject sequence is defined as the longest initial subsequence of
the input string, starting with the first non-whitespace character, that is of
the expected form.
</p>
<p>The form of numeric data is a non-empty sequence of significand digits with an
optional decimal point, and an optional exponent consisting of an exponent
prefix followed by an optional sign and a non-empty sequence of decimal
digits. A significand digit is either a decimal digit or a Latin letter (62
possible characters), with ‘<samp>A</samp>’ = 10, ‘<samp>B</samp>’ = 11, …, ‘<samp>Z</samp>’ =
35; case is ignored in bases less or equal to 36, in bases larger than 36,
‘<samp>a</samp>’ = 36, ‘<samp>b</samp>’ = 37, …, ‘<samp>z</samp>’ = 61.
The value of a
significand digit must be strictly less than the base. The decimal point can
be either the one defined by the current locale or the period (the first one
is accepted for consistency with the C standard and the practice, the second
one is accepted to allow the programmer to provide MPFR numbers from strings
in a way that does not depend on the current locale).
The exponent prefix can be ‘<samp>e</samp>’ or ‘<samp>E</samp>’ for bases up to 10, or
‘<samp>@</samp>’ in any base; it indicates a multiplication by a power of the
base. In bases 2 and 16, the exponent prefix can also be ‘<samp>p</samp>’ or ‘<samp>P</samp>’,
in which case the exponent, called <em>binary exponent</em>, indicates a
multiplication by a power of 2 instead of the base (there is a difference
only for base 16); in base 16 for example ‘<samp>1p2</samp>’ represents 4 whereas
‘<samp>1@2</samp>’ represents 256. The value of an exponent is always written in
base 10.
</p>
<p>If the argument <var>base</var> is 0, then the base is automatically detected
as follows. If the significand starts with ‘<samp>0b</samp>’ or ‘<samp>0B</samp>’, base 2
is assumed. If the significand starts with ‘<samp>0x</samp>’ or ‘<samp>0X</samp>’, base 16
is assumed. Otherwise base 10 is assumed.
</p>
<p>Note: The exponent (if present)
must contain at least a digit. Otherwise the possible
exponent prefix and sign are not part of the number (which ends with the
significand). Similarly, if ‘<samp>0b</samp>’, ‘<samp>0B</samp>’, ‘<samp>0x</samp>’ or ‘<samp>0X</samp>’
is not followed by a binary/hexadecimal digit, then the subject sequence
stops at the character ‘<samp>0</samp>’, thus 0 is read.
</p>
<p>Special data (for infinities and NaN) can be ‘<samp>@inf@</samp>’ or
‘<samp>@nan@(n-char-sequence-opt)</samp>’, and if <em><var>base</var> <= 16</em>,
it can also be ‘<samp>infinity</samp>’, ‘<samp>inf</samp>’, ‘<samp>nan</samp>’ or
‘<samp>nan(n-char-sequence-opt)</samp>’, all case insensitive.
A ‘<samp>n-char-sequence-opt</samp>’ is a possibly empty string containing only digits,
Latin letters and the underscore (0, 1, 2, …, 9, a, b, …, z,
A, B, …, Z, _). Note: one has an optional sign for all data, even
NaN.
For example, ‘<samp>-@nAn@(This_Is_Not_17)</samp>’ is a valid representation for NaN
in base 17.
</p>
</dd></dl>
<dl>
<dt><a name="index-mpfr_005fset_005fnan"></a>Function: <em>void</em> <strong>mpfr_set_nan</strong> <em>(mpfr_t <var>x</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005finf"></a>Function: <em>void</em> <strong>mpfr_set_inf</strong> <em>(mpfr_t <var>x</var>, int <var>sign</var>)</em></dt>
<dt><a name="index-mpfr_005fset_005fzero"></a>Function: <em>void</em> <strong>mpfr_set_zero</strong> <em>(mpfr_t <var>x</var>, int <var>sign</var>)</em></dt>
<dd><p>Set the variable <var>x</var> to NaN (Not-a-Number), infinity or zero respectively.
In <code>mpfr_set_inf</code> or <code>mpfr_set_zero</code>, <var>x</var> is set to plus
infinity or plus zero iff <var>sign</var> is nonnegative;
in <code>mpfr_set_nan</code>, the sign bit of the result is unspecified.
</p></dd></dl>
<dl>
<dt><a name="index-mpfr_005fswap"></a>Function: <em>void</em> <strong>mpfr_swap</strong> <em>(mpfr_t <var>x</var>, mpfr_t <var>y</var>)</em></dt>
<dd><p>Swap the structures pointed to by <var>x</var> and <var>y</var>. In particular,
the values are exchanged without rounding (this may be different from
three <code>mpfr_set</code> calls using a third auxiliary variable).
</p>
<p>Warning! Since the precisions are exchanged, this will affect future
assignments. Moreover, since the significand pointers are also exchanged,
you must not use this function if the allocation method used for <var>x</var>
and/or <var>y</var> does not permit it. This is the case when <var>x</var> and/or
<var>y</var> were declared and initialized with <code>MPFR_DECL_INIT</code>, and
possibly with <code>mpfr_custom_init_set</code> (see <a href="Custom-Interface.html#Custom-Interface">Custom Interface</a>).
</p></dd></dl>
<hr>
<div class="header">
<p>
Next: <a href="Combined-Initialization-and-Assignment-Functions.html#Combined-Initialization-and-Assignment-Functions" accesskey="n" rel="next">Combined Initialization and Assignment Functions</a>, Previous: <a href="Initialization-Functions.html#Initialization-Functions" accesskey="p" rel="prev">Initialization Functions</a>, Up: <a href="MPFR-Interface.html#MPFR-Interface" accesskey="u" rel="up">MPFR Interface</a> [<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|