Polly 19.0.0git
Classes | Typedefs | Enumerations | Functions
imath/imrat.h File Reference
#include <stdbool.h>
#include "imath.h"

Go to the source code of this file.

Classes

struct  mpq_t
 

Typedefs

typedef struct mpq_tmp_rat
 

Enumerations

enum  mp_round_mode { MP_ROUND_DOWN , MP_ROUND_HALF_UP , MP_ROUND_UP , MP_ROUND_HALF_DOWN }
 

Functions

static mp_int MP_NUMER_P (mp_rat Q)
 
static mp_int MP_DENOM_P (mp_rat Q)
 
mp_result mp_rat_init (mp_rat r)
 Initializes r with 1-digit precision and sets it to zero.
 
mp_rat mp_rat_alloc (void)
 Allocates a fresh zero-valued mpq_t on the heap, returning NULL in case of error.
 
mp_result mp_rat_reduce (mp_rat r)
 Reduces r in-place to lowest terms and canonical form.
 
mp_result mp_rat_init_size (mp_rat r, mp_size n_prec, mp_size d_prec)
 Initializes r with at least n_prec digits of storage for the numerator and d_prec digits of storage for the denominator, and value zero.
 
mp_result mp_rat_init_copy (mp_rat r, mp_rat old)
 Initializes r to be a copy of an already-initialized value in old.
 
mp_result mp_rat_set_value (mp_rat r, mp_small numer, mp_small denom)
 Sets the value of r to the ratio of signed numer to signed denom.
 
mp_result mp_rat_set_uvalue (mp_rat r, mp_usmall numer, mp_usmall denom)
 Sets the value of r to the ratio of unsigned numer to unsigned denom.
 
void mp_rat_clear (mp_rat r)
 Releases the storage used by r.
 
void mp_rat_free (mp_rat r)
 Releases the storage used by r and also r itself.
 
mp_result mp_rat_numer (mp_rat r, mp_int z)
 Sets z to a copy of the numerator of r.
 
mp_int mp_rat_numer_ref (mp_rat r)
 Returns a pointer to the numerator of r.
 
mp_result mp_rat_denom (mp_rat r, mp_int z)
 Sets z to a copy of the denominator of r.
 
mp_int mp_rat_denom_ref (mp_rat r)
 Returns a pointer to the denominator of r.
 
mp_sign mp_rat_sign (mp_rat r)
 Reports the sign of r.
 
mp_result mp_rat_copy (mp_rat a, mp_rat c)
 Sets c to a copy of the value of a.
 
void mp_rat_zero (mp_rat r)
 Sets r to zero.
 
mp_result mp_rat_abs (mp_rat a, mp_rat c)
 Sets c to the absolute value of a.
 
mp_result mp_rat_neg (mp_rat a, mp_rat c)
 Sets c to the absolute value of a.
 
mp_result mp_rat_recip (mp_rat a, mp_rat c)
 Sets c to the reciprocal of a if the reciprocal is defined.
 
mp_result mp_rat_add (mp_rat a, mp_rat b, mp_rat c)
 Sets c to the sum of a and b.
 
mp_result mp_rat_sub (mp_rat a, mp_rat b, mp_rat c)
 Sets c to the difference of a less b.
 
mp_result mp_rat_mul (mp_rat a, mp_rat b, mp_rat c)
 Sets c to the product of a and b.
 
mp_result mp_rat_div (mp_rat a, mp_rat b, mp_rat c)
 Sets c to the ratio a / b if that ratio is defined.
 
mp_result mp_rat_add_int (mp_rat a, mp_int b, mp_rat c)
 Sets c to the sum of a and integer b.
 
mp_result mp_rat_sub_int (mp_rat a, mp_int b, mp_rat c)
 Sets c to the difference of a less integer b.
 
mp_result mp_rat_mul_int (mp_rat a, mp_int b, mp_rat c)
 Sets c to the product of a and integer b.
 
mp_result mp_rat_div_int (mp_rat a, mp_int b, mp_rat c)
 Sets c to the ratio a / b if that ratio is defined.
 
mp_result mp_rat_expt (mp_rat a, mp_small b, mp_rat c)
 Sets c to the value of a raised to the b power.
 
int mp_rat_compare (mp_rat a, mp_rat b)
 Returns the comparator of a and b.
 
int mp_rat_compare_unsigned (mp_rat a, mp_rat b)
 Returns the comparator of the magnitudes of a and b, disregarding their signs.
 
int mp_rat_compare_zero (mp_rat r)
 Returns the comparator of r and zero.
 
int mp_rat_compare_value (mp_rat r, mp_small n, mp_small d)
 Returns the comparator of r and the signed ratio n / d.
 
bool mp_rat_is_integer (mp_rat r)
 Reports whether r is an integer, having canonical denominator 1.
 
mp_result mp_rat_to_ints (mp_rat r, mp_small *num, mp_small *den)
 Reports whether the numerator and denominator of r can be represented as small signed integers, and if so stores the corresponding values to num and den.
 
mp_result mp_rat_to_string (mp_rat r, mp_size radix, char *str, int limit)
 Converts r to a zero-terminated string of the format "n/d" with n and d in the specified radix and writing no more than limit bytes to the given output buffer str.
 
mp_result mp_rat_to_decimal (mp_rat r, mp_size radix, mp_size prec, mp_round_mode round, char *str, int limit)
 Converts the value of r to a string in decimal-point notation with the specified radix, writing no more than limit bytes of data to the given output buffer.
 
mp_result mp_rat_string_len (mp_rat r, mp_size radix)
 Reports the minimum number of characters required to represent r as a zero-terminated string in the given radix.
 
mp_result mp_rat_decimal_len (mp_rat r, mp_size radix, mp_size prec)
 Reports the length in bytes of the buffer needed to convert r using the mp_rat_to_decimal() function with the specified radix and prec.
 
mp_result mp_rat_read_string (mp_rat r, mp_size radix, const char *str)
 Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag.
 
mp_result mp_rat_read_cstring (mp_rat r, mp_size radix, const char *str, char **end)
 Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag.
 
mp_result mp_rat_read_ustring (mp_rat r, mp_size radix, const char *str, char **end)
 Sets r to the value represented by a zero-terminated string str having one of the following formats, each with an optional leading sign flag:
 
mp_result mp_rat_read_decimal (mp_rat r, mp_size radix, const char *str)
 Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag.
 
mp_result mp_rat_read_cdecimal (mp_rat r, mp_size radix, const char *str, char **end)
 Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag.
 

Typedef Documentation

◆ mp_rat

typedef struct mpq_t * mp_rat

Enumeration Type Documentation

◆ mp_round_mode

Enumerator
MP_ROUND_DOWN 
MP_ROUND_HALF_UP 
MP_ROUND_UP 
MP_ROUND_HALF_DOWN 

Definition at line 50 of file imath/imrat.h.

Function Documentation

◆ MP_DENOM_P()

static mp_int MP_DENOM_P ( mp_rat  Q)
inlinestatic

◆ MP_NUMER_P()

static mp_int MP_NUMER_P ( mp_rat  Q)
inlinestatic

◆ mp_rat_abs()

mp_result mp_rat_abs ( mp_rat  a,
mp_rat  c 
)

Sets c to the absolute value of a.

Definition at line 178 of file imath/imrat.c.

References a(), MP_DENOM_P(), mp_int_abs, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_add()

mp_result mp_rat_add ( mp_rat  a,
mp_rat  b,
mp_rat  c 
)

Sets c to the sum of a and b.

Definition at line 220 of file imath/imrat.c.

References a(), b(), mp_int_add, and s_rat_combine().

◆ mp_rat_add_int()

mp_result mp_rat_add_int ( mp_rat  a,
mp_int  b,
mp_rat  c 
)

Sets c to the sum of a and integer b.

Definition at line 282 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_add, mp_int_clear, mp_int_init_copy, mp_int_mul, MP_NUMER_P(), MP_OK, mp_rat_copy, res, and s_rat_reduce().

◆ mp_rat_alloc()

mp_rat mp_rat_alloc ( void  )

Allocates a fresh zero-valued mpq_t on the heap, returning NULL in case of error.

The only possible error is out-of-memory.

Definition at line 64 of file imath/imrat.c.

References MP_OK, and mp_rat_init.

◆ mp_rat_clear()

void mp_rat_clear ( mp_rat  r)

Releases the storage used by r.

Definition at line 135 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_clear, and MP_NUMER_P().

◆ mp_rat_compare()

int mp_rat_compare ( mp_rat  a,
mp_rat  b 
)

Returns the comparator of a and b.

Definition at line 378 of file imath/imrat.c.

References a(), b(), cmp(), MP_NUMER_SIGN, mp_rat_compare_unsigned, and MP_ZPOS.

◆ mp_rat_compare_unsigned()

int mp_rat_compare_unsigned ( mp_rat  a,
mp_rat  b 
)

Returns the comparator of the magnitudes of a and b, disregarding their signs.

Neither a nor b is modified by the comparison.

Definition at line 400 of file imath/imrat.c.

References a(), b(), cmp(), MP_DENOM_P(), mp_int_clear, mp_int_compare_unsigned, mp_int_init_copy, mp_int_mul, MP_NUMER_P(), MP_OK, res, SETUP, and TEMP.

◆ mp_rat_compare_value()

int mp_rat_compare_value ( mp_rat  r,
mp_small  n,
mp_small  d 
)

Returns the comparator of r and the signed ratio n / d.

It returns MP_UNDEF if d is zero.

Definition at line 434 of file imath/imrat.c.

References MP_OK, mp_rat_clear, mp_rat_compare, mp_rat_init, mp_rat_set_value, n, and res.

◆ mp_rat_compare_zero()

int mp_rat_compare_zero ( mp_rat  r)

Returns the comparator of r and zero.

Definition at line 432 of file imath/imrat.c.

References mp_int_compare_zero, and MP_NUMER_P().

◆ mp_rat_copy()

mp_result mp_rat_copy ( mp_rat  a,
mp_rat  c 
)

Sets c to a copy of the value of a.

No new memory is allocated unless a term of a has more significant digits than the corresponding term of c has allocated.

Definition at line 162 of file imath/imrat.c.

References a(), MP_DENOM_P(), mp_int_copy, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_decimal_len()

mp_result mp_rat_decimal_len ( mp_rat  r,
mp_size  radix,
mp_size  prec 
)

Reports the length in bytes of the buffer needed to convert r using the mp_rat_to_decimal() function with the specified radix and prec.

The buffer size estimate may slightly exceed the actual required capacity.

Definition at line 643 of file imath/imrat.c.

References mp_int_string_len, and MP_NUMER_P().

◆ mp_rat_denom()

mp_result mp_rat_denom ( mp_rat  r,
mp_int  z 
)

Sets z to a copy of the denominator of r.

Definition at line 154 of file imath/imrat.c.

References MP_DENOM_P(), and mp_int_copy.

◆ mp_rat_denom_ref()

mp_int mp_rat_denom_ref ( mp_rat  r)

Returns a pointer to the denominator of r.

Definition at line 158 of file imath/imrat.c.

References MP_DENOM_P().

◆ mp_rat_div()

mp_result mp_rat_div ( mp_rat  a,
mp_rat  b,
mp_rat  c 
)

Sets c to the ratio a / b if that ratio is defined.

It returns MP_UNDEF if b is zero.

Definition at line 244 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_clear, mp_int_copy, mp_int_init, mp_int_mul, MP_NUMER_P(), MP_OK, mp_rat_compare_zero, MP_UNDEF, res, and s_rat_reduce().

◆ mp_rat_div_int()

mp_result mp_rat_div_int ( mp_rat  a,
mp_int  b,
mp_rat  c 
)

Sets c to the ratio a / b if that ratio is defined.

It returns MP_UNDEF if b is zero.

Definition at line 343 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_compare_zero, mp_int_mul, MP_OK, mp_rat_copy, MP_UNDEF, res, and s_rat_reduce().

◆ mp_rat_expt()

mp_result mp_rat_expt ( mp_rat  a,
mp_small  b,
mp_rat  c 
)

Sets c to the value of a raised to the b power.

It returns MP_RANGE if b < 0.

Definition at line 359 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_expt, MP_NUMER_P(), MP_OK, mp_rat_copy, mp_rat_set_value, and res.

◆ mp_rat_free()

void mp_rat_free ( mp_rat  r)

Releases the storage used by r and also r itself.

This should only be used for r allocated by mp_rat_alloc().

Definition at line 140 of file imath/imrat.c.

References assert, mpz_t::digits, mp_rat_clear, and mpq_t::num.

◆ mp_rat_init()

mp_result mp_rat_init ( mp_rat  r)

Initializes r with 1-digit precision and sets it to zero.

This function cannot fail unless r is NULL.

Definition at line 52 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_clear, mp_int_init, mp_int_set_value, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_init_copy()

mp_result mp_rat_init_copy ( mp_rat  r,
mp_rat  old 
)

Initializes r to be a copy of an already-initialized value in old.

The new copy does not share storage with the original.

Definition at line 93 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_clear, mp_int_init_copy, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_init_size()

mp_result mp_rat_init_size ( mp_rat  r,
mp_size  n_prec,
mp_size  d_prec 
)

Initializes r with at least n_prec digits of storage for the numerator and d_prec digits of storage for the denominator, and value zero.

If either precision is zero, the default precision is used, rounded up to the nearest word size.

Definition at line 79 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_clear, mp_int_init_size, mp_int_set_value, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_is_integer()

bool mp_rat_is_integer ( mp_rat  r)

Reports whether r is an integer, having canonical denominator 1.

Definition at line 453 of file imath/imrat.c.

References MP_DENOM_P(), and mp_int_compare_value.

◆ mp_rat_mul()

mp_result mp_rat_mul ( mp_rat  a,
mp_rat  b,
mp_rat  c 
)

Sets c to the product of a and b.

Definition at line 228 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_compare_zero, mp_int_mul, MP_NUMER_P(), MP_OK, res, and s_rat_reduce().

◆ mp_rat_mul_int()

mp_result mp_rat_mul_int ( mp_rat  a,
mp_int  b,
mp_rat  c 
)

Sets c to the product of a and integer b.

Definition at line 330 of file imath/imrat.c.

References a(), b(), mp_int_mul, MP_NUMER_P(), MP_OK, mp_rat_copy, res, and s_rat_reduce().

◆ mp_rat_neg()

mp_result mp_rat_neg ( mp_rat  a,
mp_rat  c 
)

Sets c to the absolute value of a.

Definition at line 189 of file imath/imrat.c.

References a(), MP_DENOM_P(), mp_int_copy, mp_int_neg, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_numer()

mp_result mp_rat_numer ( mp_rat  r,
mp_int  z 
)

Sets z to a copy of the numerator of r.

Definition at line 148 of file imath/imrat.c.

References mp_int_copy, and MP_NUMER_P().

◆ mp_rat_numer_ref()

mp_int mp_rat_numer_ref ( mp_rat  r)

Returns a pointer to the numerator of r.

Definition at line 152 of file imath/imrat.c.

References MP_NUMER_P().

◆ mp_rat_read_cdecimal()

mp_result mp_rat_read_cdecimal ( mp_rat  r,
mp_size  radix,
const char *  str,
char **  end 
)

Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag.

It returns MP_UNDEF if the effective denominator. If end is not NULL then *end is set to point to the first unconsumed character in the string, after parsing.

Definition at line 720 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_add, mp_int_clear, mp_int_compare, mp_int_compare_zero, mp_int_div_value, mp_int_divisible_value, mp_int_init, mp_int_mul, mp_int_mul_value, mp_int_read_cstring, mp_int_set_value, MP_NEG, MP_NUMER_P(), MP_NUMER_SIGN, MP_OK, MP_TRUNC, MP_ZPOS, res, s_rat_reduce(), and str.

◆ mp_rat_read_cstring()

mp_result mp_rat_read_cstring ( mp_rat  r,
mp_size  radix,
const char *  str,
char **  end 
)

Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag.

It returns MP_UNDEF if the encoded denominator has value zero. If end is not NULL then *end is set to point to the first unconsumed character in the string, after parsing.

Definition at line 660 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_compare_zero, mp_int_read_cstring, mp_int_set_value, MP_NUMER_P(), MP_OK, MP_TRUNC, MP_UNDEF, res, s_rat_reduce(), and str.

◆ mp_rat_read_decimal()

mp_result mp_rat_read_decimal ( mp_rat  r,
mp_size  radix,
const char *  str 
)

Sets r to the value represented by a zero-terminated string str in the format "z.ffff" including a sign flag.

It returns MP_UNDEF if the effective denominator.

Definition at line 716 of file imath/imrat.c.

References mp_rat_read_cdecimal, and str.

◆ mp_rat_read_string()

mp_result mp_rat_read_string ( mp_rat  r,
mp_size  radix,
const char *  str 
)

Sets r to the value represented by a zero-terminated string str in the format "n/d" including a sign flag.

It returns MP_UNDEF if the encoded denominator has value zero.

Definition at line 656 of file imath/imrat.c.

References mp_rat_read_cstring, and str.

◆ mp_rat_read_ustring()

mp_result mp_rat_read_ustring ( mp_rat  r,
mp_size  radix,
const char *  str,
char **  end 
)

Sets r to the value represented by a zero-terminated string str having one of the following formats, each with an optional leading sign flag:

n : integer format, e.g. "123" n/d : ratio format, e.g., "-12/5" z.ffff : decimal format, e.g., "1.627"

It returns MP_UNDEF if the effective denominator is zero. If end is not NULL then *end is set to point to the first unconsumed character in the string, after parsing.

Definition at line 701 of file imath/imrat.c.

References mp_rat_read_cdecimal, mp_rat_read_cstring, MP_TRUNC, res, and str.

◆ mp_rat_recip()

mp_result mp_rat_recip ( mp_rat  a,
mp_rat  c 
)

Sets c to the reciprocal of a if the reciprocal is defined.

It returns MP_UNDEF if a is zero.

Definition at line 200 of file imath/imrat.c.

References a(), MP_DENOM_P(), MP_DENOM_SIGN, mp_int_swap, MP_NUMER_P(), MP_NUMER_SIGN, MP_OK, mp_rat_compare_zero, mp_rat_copy, MP_UNDEF, and res.

◆ mp_rat_reduce()

mp_result mp_rat_reduce ( mp_rat  r)

Reduces r in-place to lowest terms and canonical form.

Zero is represented as 0/1, one as 1/1, and signs are adjusted so that the sign of the value is carried by the numerator.

Definition at line 77 of file imath/imrat.c.

References s_rat_reduce().

◆ mp_rat_set_uvalue()

mp_result mp_rat_set_uvalue ( mp_rat  r,
mp_usmall  numer,
mp_usmall  denom 
)

Sets the value of r to the ratio of unsigned numer to unsigned denom.

It returns MP_UNDEF if denom is zero.

Definition at line 120 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_set_uvalue, MP_NUMER_P(), MP_OK, MP_UNDEF, res, and s_rat_reduce().

◆ mp_rat_set_value()

mp_result mp_rat_set_value ( mp_rat  r,
mp_small  numer,
mp_small  denom 
)

Sets the value of r to the ratio of signed numer to signed denom.

It returns MP_UNDEF if denom is zero.

Definition at line 105 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_set_value, MP_NUMER_P(), MP_OK, MP_UNDEF, res, and s_rat_reduce().

◆ mp_rat_sign()

mp_sign mp_rat_sign ( mp_rat  r)

Reports the sign of r.

Definition at line 160 of file imath/imrat.c.

References MP_NUMER_SIGN.

◆ mp_rat_string_len()

mp_result mp_rat_string_len ( mp_rat  r,
mp_size  radix 
)

Reports the minimum number of characters required to represent r as a zero-terminated string in the given radix.

Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.

Definition at line 627 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_compare_zero, mp_int_string_len, and MP_NUMER_P().

◆ mp_rat_sub()

mp_result mp_rat_sub ( mp_rat  a,
mp_rat  b,
mp_rat  c 
)

Sets c to the difference of a less b.

Definition at line 224 of file imath/imrat.c.

References a(), b(), mp_int_sub, and s_rat_combine().

◆ mp_rat_sub_int()

mp_result mp_rat_sub_int ( mp_rat  a,
mp_int  b,
mp_rat  c 
)

Sets c to the difference of a less integer b.

Definition at line 306 of file imath/imrat.c.

References a(), b(), MP_DENOM_P(), mp_int_clear, mp_int_init_copy, mp_int_mul, mp_int_sub, MP_NUMER_P(), MP_OK, mp_rat_copy, res, and s_rat_reduce().

◆ mp_rat_to_decimal()

mp_result mp_rat_to_decimal ( mp_rat  r,
mp_size  radix,
mp_size  prec,
mp_round_mode  round,
char *  str,
int  limit 
)

Converts the value of r to a string in decimal-point notation with the specified radix, writing no more than limit bytes of data to the given output buffer.

It generates prec digits of precision, and requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.

Ratios usually must be rounded when they are being converted for output as a decimal value. There are four rounding modes currently supported:

MP_ROUND_DOWN Truncates the value toward zero. Example: 12.009 to 2dp becomes 12.00

MP_ROUND_UP Rounds the value away from zero: Example: 12.001 to 2dp becomes 12.01, but 12.000 to 2dp remains 12.00

MP_ROUND_HALF_DOWN Rounds the value to nearest digit, half goes toward zero. Example: 12.005 to 2dp becomes 12.00, but 12.006 to 2dp becomes 12.01

MP_ROUND_HALF_UP Rounds the value to nearest digit, half rounds upward. Example: 12.005 to 2dp becomes 12.01, but 12.004 to 2dp becomes 12.00

Definition at line 494 of file imath/imrat.c.

References cmp(), MP_BADARG, MP_DENOM_P(), mp_int_abs, mp_int_add_value, mp_int_clear, mp_int_compare, mp_int_compare_zero, mp_int_div, mp_int_expt_value, mp_int_init, mp_int_init_copy, mp_int_mul, mp_int_mul_pow2, mp_int_mul_value, mp_int_to_string, MP_NEG, MP_NUMER_P(), MP_NUMER_SIGN, MP_OK, MP_ROUND_DOWN, MP_ROUND_HALF_DOWN, MP_ROUND_HALF_UP, MP_ROUND_UP, MP_TRUNC, res, SETUP, str, and TEMP.

◆ mp_rat_to_ints()

mp_result mp_rat_to_ints ( mp_rat  r,
mp_small num,
mp_small den 
)

Reports whether the numerator and denominator of r can be represented as small signed integers, and if so stores the corresponding values to num and den.

It returns MP_RANGE if either cannot be so represented.

Definition at line 457 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_to_int, MP_NUMER_P(), MP_OK, and res.

◆ mp_rat_to_string()

mp_result mp_rat_to_string ( mp_rat  r,
mp_size  radix,
char *  str,
int  limit 
)

Converts r to a zero-terminated string of the format "n/d" with n and d in the specified radix and writing no more than limit bytes to the given output buffer str.

The output of the numerator includes a sign flag if r is negative. Requires MP_MIN_RADIX <= radix <= MP_MAX_RADIX.

Definition at line 468 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_compare_zero, mp_int_to_string, MP_NUMER_P(), MP_OK, MP_TRUNC, res, and str.

◆ mp_rat_zero()

void mp_rat_zero ( mp_rat  r)

Sets r to zero.

The allocated storage of r is not changed.

Definition at line 173 of file imath/imrat.c.

References MP_DENOM_P(), mp_int_set_value, mp_int_zero, and MP_NUMER_P().