Next: Formatted Output Functions, Previous: Special Functions, Up: MPFR Interface [Index]

### 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 string of digits in base base, rounded in the direction rnd. The base may vary from 2 to 62. Print n significant digits exactly, or if n is 0, enough digits so that op can be read back exactly (see `mpfr_get_str`).

  In addition to the significant digits, a decimal point (defined by the current locale) at the right of the first digit and a trailing exponent in base 10, in the form ‘`eNNN`’, are printed. If base is greater than 10, ‘`@`’ will be used instead of ‘`e`’ as exponent delimiter.

  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.

  This function reads a word (defined as a sequence of characters between whitespace) 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, or if 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 a 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.

Next: Formatted Output Functions, Previous: Special Functions, Up: MPFR Interface [Index]