Next: Integer Arithmetic, Previous: Simultaneous Integer Init & Assign, Up: Integer Functions [Index]
This section describes functions for converting MPIR integers to standard C types. Functions for converting to MPIR integers are described in Assigning Integers and I/O of Integers.
Return the value of op as an mpir_ui
.
If op is too big to fit an mpir_ui
then just the least
significant bits that do fit are returned. The sign of op is ignored,
only the absolute value is used.
If op fits into a mpir_si
return the value of op.
Otherwise return the least significant part of op, with the same sign
as op.
If op is too big to fit in a mpir_si
, the returned
result is probably not very useful. To find out if the value will fit, use
the function mpz_fits_slong_p
.
Return the value of op as an uintmax_t
.
If op is too big to fit an uintmax_t
then just the least
significant bits that do fit are returned. The sign of op is ignored,
only the absolute value is used. Note this function is only available if you
include stdint.h before including mpir.h.
If op fits into a intmax_t
return the value of op.
Otherwise return the least significant part of op, with the same sign
as op.
If op is too big to fit in a intmax_t
, the returned
result is probably not very useful. Note this function is only available if you
include the stdint.h header before including mpir.h.
Convert op to a double
, truncating if necessary (ie. rounding
towards zero).
If the exponent from the conversion is too big, the result is system dependent. An infinity is returned where available. A hardware overflow trap may or may not occur.
Convert op to a double
, truncating if necessary (ie. rounding
towards zero), and returning the exponent separately.
The return value is in the range 0.5<=abs(d)<1 and the
exponent is stored to *exp
. d *
2^exp is the (truncated) op value. If op is zero, the
return is 0.0 and 0 is stored to *exp
.
This is similar to the standard C frexp
function (see Normalization
Functions in The GNU C Library Reference Manual).
Convert op to a string of digits in base base. The base may vary from 2 to 36 or from -2 to -36.
For base 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.
If str is NULL
, the result string is allocated using the current
allocation function (see Custom Allocation). The block will be
strlen(str)+1
bytes, that being exactly enough for the string and
null-terminator.
If str is not NULL
, it should point to a block of storage large
enough for the result, that being mpz_sizeinbase (op, base)
+ 2
. The two extra bytes are for a possible minus sign, and the
null-terminator.
A pointer to the result string is returned, being either the allocated block, or the given str.
Next: Integer Arithmetic, Previous: Simultaneous Integer Init & Assign, Up: Integer Functions [Index]