Input and Output Functions (GNU MPFR 4.2.1)
Description: How to install and use GNU MPFR, a library for reliable multiple precision floating-point arithmetic, version 4.2.1.

### 5.8 Input and Output Functions

This section describes functions that perform input from an input/output stream, and functions that output to an input/output stream. Passing a null pointer for a `stream` to any of these functions will make them read from `stdin` and write to `stdout`, respectively.

When using a function that takes a `FILE *` argument, you must include the `<stdio.h>` standard header before `mpfr.h`, to allow `mpfr.h` to define prototypes for these functions.

Function: `size_t` mpfr_out_str `(FILE *stream, int base, size_t n, mpfr_t op, mpfr_rnd_t rnd)` ¶

  Output op on stream stream as a text string in base abs(base), rounded in the direction rnd. The base may vary from 2 to 62 or from −2 to −36 (any other value yields undefined behavior). The argument n has the same meaning as in `mpfr_get_str` (see mpfr_get_str): Print n significant digits exactly, or if n is 0, the number `mpfr_get_str_ndigits (base, p)`, where p is the precision of op (see mpfr_get_str_ndigits).

  If the input is NaN, +Inf, −Inf, +0, or −0, then ‘`@NaN@`’, ‘`@Inf@`’, ‘`-@Inf@`’, ‘`0`’, or ‘`-0`’ is output, respectively.

  For the regular numbers, the format of the output is the following: the most significant digit, then a decimal-point character (defined by the current locale), then the remaining n − 1 digits (including trailing zeros), then the exponent prefix, then the exponent in decimal. The exponent prefix is ‘`e`’ when abs(base) <= 10, and ‘`@`’ when abs(base) > 10. See mpfr_get_str for information on the digits depending on the base.

  Return the number of characters written, or if an error occurred, return 0.

Function: `size_t` mpfr_inp_str `(mpfr_t rop, FILE *stream, int base, mpfr_rnd_t rnd)` ¶

  Input a string in base base from stream stream, rounded in the direction rnd, and put the read float in rop.

  After skipping optional whitespace (as defined by `isspace`, which depends on the current locale), this function reads a word, defined as the longest sequence of non-whitespace characters, and parses it using `mpfr_set_str`. See the documentation of `mpfr_strtofr` for a detailed description of the valid string formats.

  Return the number of bytes read (including the leading whitespace, if any), or if the string format is invalid or an error occurred, return 0.

Function: `int` mpfr_fpif_export `(FILE *stream, mpfr_t op)` ¶

  Export the number op to the stream stream in a floating-point interchange format. In particular one can export on a 32-bit computer and import on a 64-bit computer, or export on a little-endian computer and import on a big-endian computer. The precision of op and the sign bit of a NaN are stored too. Return 0 iff the export was successful.

  Note: this function is experimental and its interface might change in future versions.

Function: `int` mpfr_fpif_import `(mpfr_t op, FILE *stream)` ¶

  Import the number op from the stream stream in a floating-point interchange format (see `mpfr_fpif_export`). Note that the precision of op is set to the one read from the stream, and the sign bit is always retrieved (even for NaN). If the stored precision is zero or greater than `MPFR_PREC_MAX`, the function fails (it returns non-zero) and op is unchanged. If the function fails for another reason, op is set to NaN and it is unspecified whether the precision of op has changed to the one read from the file. Return 0 iff the import was successful.

  Note: this function is experimental and its interface might change in future versions.

Function: `void` mpfr_dump `(mpfr_t op)` ¶

  Output op on `stdout` in some unspecified format, then a newline character. This function is mainly for debugging purpose. Thus invalid data may be supported. Everything that is not specified may change without breaking the ABI and may depend on the environment.

  The current output format is the following: a minus sign if the sign bit is set (even for NaN); ‘`@NaN@`’, ‘`@Inf@`’ or ‘`0`’ if the argument is NaN, an infinity or zero, respectively; otherwise the remaining of the output is as follows: ‘`0.`’ then the p bits of the binary significand, where p is the precision of the number; if the trailing bits are not all zeros (which must not occur with valid data), they are output enclosed by square brackets; the character ‘`E`’ followed by the exponent written in base 10; in case of invalid data or out-of-range exponent, this function outputs three exclamation marks (‘`!!!`’), followed by flags, followed by three exclamation marks (‘`!!!`’) again. These flags are: ‘`N`’ if the most significant bit of the significand is 0 (i.e., the number is not normalized); ‘`T`’ if there are non-zero trailing bits; ‘`U`’ if this is an UBF number (internal use only); ‘`<`’ if the exponent is less than the current minimum exponent; ‘`>`’ if the exponent is greater than the current maximum exponent.