Lines Matching +full:- +full:a
1 <!--
4 -->
17 By default, the Makefile assumes you can use 64-bit integer types, even
19 `-DUSE_32BIT_WORDS` to the compiler options.
30 the library's routines. The integer library is just a single source file, so
38 number. The type `mp_int` is a pointer to an `mpz_t`, and `mp_rat` is a
41 Most of the functions in the imath library return a value of type `mp_result`.
42 This is a signed integer type which can be used to convey status information
43 and also return small values. Any negative value is considered to be a status
47 | ----------- | -------------------------------------------- |
57 If you obtain a zero or negative value of an `mp_result`, you can use the
58 `mp_error_string()` routine to obtain a pointer to a brief human-readable
60 need not be freed by the caller; the same strings are re-used from call to
65 add a number to itself and replace the original by writing:
67 mp_int_add(a, a, a); /* a = a + a */
70 below (if you discover that this is not so, please report it as a bug; I will
78 > ------------
82 > - English description.
93 | --------------- | ----------------------------------------
94 | `MP_DIGIT_BIT` | the number of bits in a single `mpz_t` digit.
95 | `MP_WORD_BIT` | the number of bits in a `mpz_t` word.
105 initialized with a certain minimum amount of storage for digits, and the
109 ------------
110 <a id="mp_int_init"></a><pre>
111 mp_result <a href="imath.h#L115">mp_int_init</a>(mp_int z);
113 - Initializes `z` with 1-digit precision and sets it to zero. This function
116 ------------
117 <a id="mp_int_alloc"></a><pre>
118 mp_int <a href="imath.h#L119">mp_int_alloc</a>(void);
120 - Allocates a fresh zero-valued `mpz_t` on the heap, returning NULL in case
121 of error. The only possible error is out-of-memory.
123 ------------
124 <a id="mp_int_init_size"></a><pre>
125 mp_result <a href="imath.h#L124">mp_int_init_size</a>(mp_int z, mp_size prec);
127 - Initializes `z` with at least `prec` digits of storage, and sets it to
131 ------------
132 <a id="mp_int_init_copy"></a><pre>
133 mp_result <a href="imath.h#L128">mp_int_init_copy</a>(mp_int z, mp_int old);
135 - Initializes `z` to be a copy of an already-initialized value in `old`. The
138 ------------
139 <a id="mp_int_init_value"></a><pre>
140 mp_result <a href="imath.h#L131">mp_int_init_value</a>(mp_int z, mp_small value);
142 - Initializes `z` to the specified signed `value` at default precision.
150 ------------
151 <a id="mp_int_clear"></a><pre>
152 void <a href="imath.h#L143">mp_int_clear</a>(mp_int z);
154 - Releases the storage used by `z`.
156 ------------
157 <a id="mp_int_free"></a><pre>
158 void <a href="imath.h#L147">mp_int_free</a>(mp_int z);
160 - Releases the storage used by `z` and also `z` itself.
167 To set an `mp_int` which has already been initialized to a small integer value,
170 ------------
171 <a id="mp_int_set_value"></a><pre>
172 mp_result <a href="imath.h#L137">mp_int_set_value</a>(mp_int z, mp_small value);
174 - Sets `z` to the value of the specified signed `value`.
176 ------------
177 <a id="mp_int_set_uvalue"></a><pre>
178 mp_result <a href="imath.h#L140">mp_int_set_uvalue</a>(mp_int z, mp_usmall uvalue);
180 - Sets `z` to the value of the specified unsigned `value`.
186 ------------
187 <a id="mp_int_copy"></a><pre>
188 mp_result <a href="imath.h#L151">mp_int_copy</a>(mp_int a, mp_int c);
190 - Replaces the value of `c` with a copy of the value of `a`. No new memory is
191 allocated unless `a` has more significant digits than `c` has allocated.
197 ------------
198 <a id="mp_int_is_odd"></a><pre>
199 static inline bool <a href="imath.h#L108">mp_int_is_odd</a>(mp_int z);
201 - Reports whether `z` is odd, having remainder 1 when divided by 2.
203 ------------
204 <a id="mp_int_is_even"></a><pre>
205 static inline bool <a href="imath.h#L111">mp_int_is_even</a>(mp_int z);
207 - Reports whether `z` is even, having remainder 0 when divided by 2.
209 ------------
210 <a id="mp_int_zero"></a><pre>
211 void <a href="imath.h#L157">mp_int_zero</a>(mp_int z);
213 - Sets `z` to zero. The allocated storage of `z` is not changed.
215 ------------
216 <a id="mp_int_abs"></a><pre>
217 mp_result <a href="imath.h#L160">mp_int_abs</a>(mp_int a, mp_int c);
219 - Sets `c` to the absolute value of `a`.
221 ------------
222 <a id="mp_int_neg"></a><pre>
223 mp_result <a href="imath.h#L163">mp_int_neg</a>(mp_int a, mp_int c);
225 - Sets `c` to the additive inverse (negation) of `a`.
227 ------------
228 <a id="mp_int_add"></a><pre>
229 mp_result <a href="imath.h#L166">mp_int_add</a>(mp_int a, mp_int b, mp_int c);
231 - Sets `c` to the sum of `a` and `b`.
233 ------------
234 <a id="mp_int_add_value"></a><pre>
235 mp_result <a href="imath.h#L169">mp_int_add_value</a>(mp_int a, mp_small value, mp_int c);
237 - Sets `c` to the sum of `a` and `value`.
239 ------------
240 <a id="mp_int_sub"></a><pre>
241 mp_result <a href="imath.h#L172">mp_int_sub</a>(mp_int a, mp_int b, mp_int c);
243 - Sets `c` to the difference of `a` less `b`.
245 ------------
246 <a id="mp_int_sub_value"></a><pre>
247 mp_result <a href="imath.h#L175">mp_int_sub_value</a>(mp_int a, mp_small value, mp_int c);
249 - Sets `c` to the difference of `a` less `value`.
251 ------------
252 <a id="mp_int_mul"></a><pre>
253 mp_result <a href="imath.h#L178">mp_int_mul</a>(mp_int a, mp_int b, mp_int c);
255 - Sets `c` to the product of `a` and `b`.
257 ------------
258 <a id="mp_int_mul_value"></a><pre>
259 mp_result <a href="imath.h#L181">mp_int_mul_value</a>(mp_int a, mp_small value, mp_int c);
261 - Sets `c` to the product of `a` and `value`.
263 ------------
264 <a id="mp_int_mul_pow2"></a><pre>
265 mp_result <a href="imath.h#L184">mp_int_mul_pow2</a>(mp_int a, mp_small p2, mp_int c);
267 - Sets `c` to the product of `a` and `2^p2`. Requires `p2 >= 0`.
269 ------------
270 <a id="mp_int_sqr"></a><pre>
271 mp_result <a href="imath.h#L187">mp_int_sqr</a>(mp_int a, mp_int c);
273 - Sets `c` to the square of `a`.
275 ------------
276 <a id="mp_int_root"></a><pre>
277 mp_result <a href="imath.h#L306">mp_int_root</a>(mp_int a, mp_small b, mp_int c);
279 - Sets `c` to the greatest integer not less than the `b`th root of `a`,
280 using Newton's root-finding algorithm.
281 It returns `MP_UNDEF` if `a < 0` and `b` is even.
283 ------------
284 <a id="mp_int_sqrt"></a><pre>
285 static inline mp_result <a href="imath.h#L310">mp_int_sqrt</a>(mp_int a, mp_int c);
287 - Sets `c` to the greatest integer not less than the square root of `a`.
288 This is a special case of `mp_int_root()`.
290 ------------
291 <a id="mp_int_div"></a><pre>
292 mp_result <a href="imath.h#L195">mp_int_div</a>(mp_int a, mp_int b, mp_int q, mp_int r);
294 - Sets `q` and `r` to the quotent and remainder of `a / b`. Division by
301 ------------
302 <a id="mp_int_div_value"></a><pre>
303 mp_result <a href="imath.h#L200">mp_int_div_value</a>(mp_int a, mp_small value, mp_int q, mp_small …
305 - Sets `q` and `*r` to the quotent and remainder of `a / value`. Division by
309 ------------
310 <a id="mp_int_div_pow2"></a><pre>
311 mp_result <a href="imath.h#L206">mp_int_div_pow2</a>(mp_int a, mp_small p2, mp_int q, mp_int r);
313 - Sets `q` and `r` to the quotient and remainder of `a / 2^p2`. This is a
318 ------------
319 <a id="mp_int_mod"></a><pre>
320 mp_result <a href="imath.h#L210">mp_int_mod</a>(mp_int a, mp_int m, mp_int c);
322 - Sets `c` to the remainder of `a / m`.
325 ------------
326 <a id="mp_int_mod_value"></a><pre>
327 static inline mp_result <a href="imath.h#L226">mp_int_mod_value</a>(mp_int a, mp_small value, mp_sm…
329 - Sets `*r` to the remainder of `a / value`.
332 ------------
333 <a id="mp_int_expt"></a><pre>
334 mp_result <a href="imath.h#L214">mp_int_expt</a>(mp_int a, mp_small b, mp_int c);
336 - Sets `c` to the value of `a` raised to the `b` power.
339 ------------
340 <a id="mp_int_expt_value"></a><pre>
341 mp_result <a href="imath.h#L218">mp_int_expt_value</a>(mp_small a, mp_small b, mp_int c);
343 - Sets `c` to the value of `a` raised to the `b` power.
346 ------------
347 <a id="mp_int_expt_full"></a><pre>
348 mp_result <a href="imath.h#L222">mp_int_expt_full</a>(mp_int a, mp_int b, mp_int c);
350 - Sets `c` to the value of `a` raised to the `b` power.
357 Unless otherwise specified, comparison between values `x` and `y` returns a
361 ------------
362 <a id="mp_int_compare"></a><pre>
363 int <a href="imath.h#L232">mp_int_compare</a>(mp_int a, mp_int b);
365 - Returns the comparator of `a` and `b`.
367 ------------
368 <a id="mp_int_compare_unsigned"></a><pre>
369 int <a href="imath.h#L236">mp_int_compare_unsigned</a>(mp_int a, mp_int b);
371 - Returns the comparator of the magnitudes of `a` and `b`, disregarding their
372 signs. Neither `a` nor `b` is modified by the comparison.
374 ------------
375 <a id="mp_int_compare_zero"></a><pre>
376 int <a href="imath.h#L239">mp_int_compare_zero</a>(mp_int z);
378 - Returns the comparator of `z` and zero.
380 ------------
381 <a id="mp_int_compare_value"></a><pre>
382 int <a href="imath.h#L242">mp_int_compare_value</a>(mp_int z, mp_small v);
384 - Returns the comparator of `z` and the signed value `v`.
386 ------------
387 <a id="mp_int_compare_uvalue"></a><pre>
388 int <a href="imath.h#L245">mp_int_compare_uvalue</a>(mp_int z, mp_usmall uv);
390 - Returns the comparator of `z` and the unsigned value `uv`.
392 ------------
393 <a id="mp_int_divisible_value"></a><pre>
394 bool <a href="imath.h#L248">mp_int_divisible_value</a>(mp_int a, mp_small v);
396 - Reports whether `a` is divisible by `v`.
398 ------------
399 <a id="mp_int_is_pow2"></a><pre>
400 int <a href="imath.h#L252">mp_int_is_pow2</a>(mp_int z);
402 - Returns `k >= 0` such that `z` is `2^k`, if such a `k` exists. If no such
403 `k` exists, the function returns -1.
409 ------------
410 <a id="mp_int_exptmod"></a><pre>
411 mp_result <a href="imath.h#L256">mp_int_exptmod</a>(mp_int a, mp_int b, mp_int m, mp_int c);
413 - Sets `c` to the value of `a` raised to the `b` power, reduced modulo `m`.
416 ------------
417 <a id="mp_int_exptmod_evalue"></a><pre>
418 mp_result <a href="imath.h#L260">mp_int_exptmod_evalue</a>(mp_int a, mp_small value, mp_int m, mp_i…
420 - Sets `c` to the value of `a` raised to the `value` power, modulo `m`.
423 ------------
424 <a id="mp_int_exptmod_bvalue"></a><pre>
425 mp_result <a href="imath.h#L264">mp_int_exptmod_bvalue</a>(mp_small value, mp_int b, mp_int m, mp_i…
427 - Sets `c` to the value of `value` raised to the `b` power, modulo `m`.
430 ------------
431 <a id="mp_int_exptmod_known"></a><pre>
432 mp_result <a href="imath.h#L271">mp_int_exptmod_known</a>(mp_int a, mp_int b, mp_int m, mp_int mu, …
434 - Sets `c` to the value of `a` raised to the `b` power, reduced modulo `m`,
435 given a precomputed reduction constant `mu` defined for Barrett's modular
440 ------------
441 <a id="mp_int_redux_const"></a><pre>
442 mp_result <a href="imath.h#L275">mp_int_redux_const</a>(mp_int m, mp_int c);
444 - Sets `c` to the reduction constant for Barrett reduction by modulus `m`.
447 ------------
448 <a id="mp_int_invmod"></a><pre>
449 mp_result <a href="imath.h#L282">mp_int_invmod</a>(mp_int a, mp_int m, mp_int c);
451 - Sets `c` to the multiplicative inverse of `a` modulo `m`, if it exists.
452 The least non-negative representative of the congruence class is computed.
454 It returns `MP_UNDEF` if the inverse does not exist, or `MP_RANGE` if `a ==
457 ------------
458 <a id="mp_int_gcd"></a><pre>
459 mp_result <a href="imath.h#L288">mp_int_gcd</a>(mp_int a, mp_int b, mp_int c);
461 - Sets `c` to the greatest common divisor of `a` and `b`.
463 It returns `MP_UNDEF` if the GCD is undefined, such as for example if `a`
466 ------------
467 <a id="mp_int_egcd"></a><pre>
468 mp_result <a href="imath.h#L295">mp_int_egcd</a>(mp_int a, mp_int b, mp_int c, mp_int x, mp_int y);
470 - Sets `c` to the greatest common divisor of `a` and `b`, and sets `x` and
471 `y` to values satisfying Bezout's identity `gcd(a, b) = ax + by`.
473 It returns `MP_UNDEF` if the GCD is undefined, such as for example if `a`
476 ------------
477 <a id="mp_int_lcm"></a><pre>
478 mp_result <a href="imath.h#L301">mp_int_lcm</a>(mp_int a, mp_int b, mp_int c);
480 - Sets `c` to the least common multiple of `a` and `b`.
482 It returns `MP_UNDEF` if the LCM is undefined, such as for example if `a`
489 ------------
490 <a id="mp_int_to_int"></a><pre>
491 mp_result <a href="imath.h#L315">mp_int_to_int</a>(mp_int z, mp_small *out);
493 - Returns `MP_OK` if `z` is representable as `mp_small`, else `MP_RANGE`.
496 ------------
497 <a id="mp_int_to_uint"></a><pre>
498 mp_result <a href="imath.h#L319">mp_int_to_uint</a>(mp_int z, mp_usmall *out);
500 - Returns `MP_OK` if `z` is representable as `mp_usmall`, or `MP_RANGE`.
503 ------------
504 <a id="mp_int_to_string"></a><pre>
505 mp_result <a href="imath.h#L327">mp_int_to_string</a>(mp_int z, mp_size radix, char *str, int limit…
507 - Converts `z` to a zero-terminated string of characters in the specified
509 terminating NUL value. A leading `-` is used to indicate a negative value.
514 ------------
515 <a id="mp_int_string_len"></a><pre>
516 mp_result <a href="imath.h#L332">mp_int_string_len</a>(mp_int z, mp_size radix);
518 - Reports the minimum number of characters required to represent `z` as a
519 zero-terminated string in the given `radix`.
522 ------------
523 <a id="mp_int_read_string"></a><pre>
524 mp_result <a href="imath.h#L347">mp_int_read_string</a>(mp_int z, mp_size radix, const char *str);
526 - Reads a string of ASCII digits in the specified `radix` from the zero
528 `A`..`Z` or `a`..`z` are accepted. Letters are interpreted without respect
531 Leading whitespace is ignored, and a leading `+` or `-` is interpreted as a
532 sign flag. Processing stops when a NUL or any other character out of range
533 for a digit in the given radix is encountered.
540 ------------
541 <a id="mp_int_read_cstring"></a><pre>
542 mp_result <a href="imath.h#L365">mp_int_read_cstring</a>(mp_int z, mp_size radix, const char *str, …
544 - Reads a string of ASCII digits in the specified `radix` from the zero
546 `A`..`Z` or `a`..`z` are accepted. Letters are interpreted without respect
549 Leading whitespace is ignored, and a leading `+` or `-` is interpreted as a
550 sign flag. Processing stops when a NUL or any other character out of range
551 for a digit in the given radix is encountered.
561 ------------
562 <a id="mp_int_count_bits"></a><pre>
563 mp_result <a href="imath.h#L368">mp_int_count_bits</a>(mp_int z);
565 - Returns the number of significant bits in `z`.
567 ------------
568 <a id="mp_int_to_binary"></a><pre>
569 mp_result <a href="imath.h#L383">mp_int_to_binary</a>(mp_int z, unsigned char *buf, int limit);
571 - Converts `z` to 2's complement binary, writing at most `limit` bytes into
576 The binary representation of `z` is in base-256 with digits ordered from
578 high-order bit of the first byte is set for negative values, clear for
579 non-negative values.
581 As a result, non-negative values will be padded with a leading zero byte if
582 the high-order byte of the base-256 magnitude is set. This extra byte is
585 ------------
586 <a id="mp_int_read_binary"></a><pre>
587 mp_result <a href="imath.h#L388">mp_int_read_binary</a>(mp_int z, unsigned char *buf, int len);
589 - Reads a 2's complement binary value from `buf` into `z`, where `len` is the
593 ------------
594 <a id="mp_int_binary_len"></a><pre>
595 mp_result <a href="imath.h#L391">mp_int_binary_len</a>(mp_int z);
597 - Returns the number of bytes to represent `z` in 2's complement binary.
599 ------------
600 <a id="mp_int_to_unsigned"></a><pre>
601 mp_result <a href="imath.h#L402">mp_int_to_unsigned</a>(mp_int z, unsigned char *buf, int limit);
603 - Converts the magnitude of `z` to unsigned binary, writing at most `limit`
610 The binary representation of `z` is in base-256 with digits ordered from
613 ------------
614 <a id="mp_int_read_unsigned"></a><pre>
615 mp_result <a href="imath.h#L407">mp_int_read_unsigned</a>(mp_int z, unsigned char *buf, int len);
617 - Reads an unsigned binary value from `buf` into `z`, where `len` is the
621 ------------
622 <a id="mp_int_unsigned_len"></a><pre>
623 mp_result <a href="imath.h#L411">mp_int_unsigned_len</a>(mp_int z);
625 - Returns the number of bytes required to represent `z` as an unsigned binary
634 there is a more efficient algorithm usually attributed to Karatsuba and Ofman
639 by a static digit threshold defined in `imath.c`. Values with fewer significant
642 `findthreshold.py` script (Python) can help you find a suitable value for for
645 ------------
646 <a id="mp_error_string"></a><pre>
647 const char *<a href="imath.h#L416">mp_error_string</a>(mp_result res);
649 - Returns a pointer to a brief, human-readable, zero-terminated string
657 ------------
658 <a id="mp_rat_init"></a><pre>
659 mp_result <a href="imrat.h#L59">mp_rat_init</a>(mp_rat r);
661 - Initializes `r` with 1-digit precision and sets it to zero. This function
664 ------------
665 <a id="mp_rat_alloc"></a><pre>
666 mp_rat <a href="imrat.h#L63">mp_rat_alloc</a>(void);
668 - Allocates a fresh zero-valued `mpq_t` on the heap, returning NULL in case
669 of error. The only possible error is out-of-memory.
671 ------------
672 <a id="mp_rat_reduce"></a><pre>
673 mp_result <a href="imrat.h#L69">mp_rat_reduce</a>(mp_rat r);
675 - Reduces `r` in-place to lowest terms and canonical form.
680 ------------
681 <a id="mp_rat_init_size"></a><pre>
682 mp_result <a href="imrat.h#L76">mp_rat_init_size</a>(mp_rat r, mp_size n_prec, mp_size d_prec);
684 - Initializes `r` with at least `n_prec` digits of storage for the numerator
690 ------------
691 <a id="mp_rat_init_copy"></a><pre>
692 mp_result <a href="imrat.h#L80">mp_rat_init_copy</a>(mp_rat r, mp_rat old);
694 - Initializes `r` to be a copy of an already-initialized value in `old`. The
697 ------------
698 <a id="mp_rat_set_value"></a><pre>
699 mp_result <a href="imrat.h#L84">mp_rat_set_value</a>(mp_rat r, mp_small numer, mp_small denom);
701 - Sets the value of `r` to the ratio of signed `numer` to signed `denom`. It
704 ------------
705 <a id="mp_rat_set_uvalue"></a><pre>
706 mp_result <a href="imrat.h#L88">mp_rat_set_uvalue</a>(mp_rat r, mp_usmall numer, mp_usmall denom);
708 - Sets the value of `r` to the ratio of unsigned `numer` to unsigned
711 ------------
712 <a id="mp_rat_clear"></a><pre>
713 void <a href="imrat.h#L91">mp_rat_clear</a>(mp_rat r);
715 - Releases the storage used by `r`.
717 ------------
718 <a id="mp_rat_free"></a><pre>
719 void <a href="imrat.h#L95">mp_rat_free</a>(mp_rat r);
721 - Releases the storage used by `r` and also `r` itself.
724 ------------
725 <a id="mp_rat_numer"></a><pre>
726 mp_result <a href="imrat.h#L98">mp_rat_numer</a>(mp_rat r, mp_int z);
728 - Sets `z` to a copy of the numerator of `r`.
730 ------------
731 <a id="mp_rat_numer_ref"></a><pre>
732 mp_int <a href="imrat.h#L101">mp_rat_numer_ref</a>(mp_rat r);
734 - Returns a pointer to the numerator of `r`.
736 ------------
737 <a id="mp_rat_denom"></a><pre>
738 mp_result <a href="imrat.h#L104">mp_rat_denom</a>(mp_rat r, mp_int z);
740 - Sets `z` to a copy of the denominator of `r`.
742 ------------
743 <a id="mp_rat_denom_ref"></a><pre>
744 mp_int <a href="imrat.h#L107">mp_rat_denom_ref</a>(mp_rat r);
746 - Returns a pointer to the denominator of `r`.
748 ------------
749 <a id="mp_rat_sign"></a><pre>
750 mp_sign <a href="imrat.h#L110">mp_rat_sign</a>(mp_rat r);
752 - Reports the sign of `r`.
754 ------------
755 <a id="mp_rat_copy"></a><pre>
756 mp_result <a href="imrat.h#L115">mp_rat_copy</a>(mp_rat a, mp_rat c);
758 - Sets `c` to a copy of the value of `a`. No new memory is allocated unless a
759 term of `a` has more significant digits than the corresponding term of `c`
762 ------------
763 <a id="mp_rat_zero"></a><pre>
764 void <a href="imrat.h#L118">mp_rat_zero</a>(mp_rat r);
766 - Sets `r` to zero. The allocated storage of `r` is not changed.
768 ------------
769 <a id="mp_rat_abs"></a><pre>
770 mp_result <a href="imrat.h#L121">mp_rat_abs</a>(mp_rat a, mp_rat c);
772 - Sets `c` to the absolute value of `a`.
774 ------------
775 <a id="mp_rat_neg"></a><pre>
776 mp_result <a href="imrat.h#L124">mp_rat_neg</a>(mp_rat a, mp_rat c);
778 - Sets `c` to the absolute value of `a`.
780 ------------
781 <a id="mp_rat_recip"></a><pre>
782 mp_result <a href="imrat.h#L128">mp_rat_recip</a>(mp_rat a, mp_rat c);
784 - Sets `c` to the reciprocal of `a` if the reciprocal is defined.
785 It returns `MP_UNDEF` if `a` is zero.
787 ------------
788 <a id="mp_rat_add"></a><pre>
789 mp_result <a href="imrat.h#L131">mp_rat_add</a>(mp_rat a, mp_rat b, mp_rat c);
791 - Sets `c` to the sum of `a` and `b`.
793 ------------
794 <a id="mp_rat_sub"></a><pre>
795 mp_result <a href="imrat.h#L134">mp_rat_sub</a>(mp_rat a, mp_rat b, mp_rat c);
797 - Sets `c` to the difference of `a` less `b`.
799 ------------
800 <a id="mp_rat_mul"></a><pre>
801 mp_result <a href="imrat.h#L137">mp_rat_mul</a>(mp_rat a, mp_rat b, mp_rat c);
803 - Sets `c` to the product of `a` and `b`.
805 ------------
806 <a id="mp_rat_div"></a><pre>
807 mp_result <a href="imrat.h#L141">mp_rat_div</a>(mp_rat a, mp_rat b, mp_rat c);
809 - Sets `c` to the ratio `a / b` if that ratio is defined.
812 ------------
813 <a id="mp_rat_add_int"></a><pre>
814 mp_result <a href="imrat.h#L144">mp_rat_add_int</a>(mp_rat a, mp_int b, mp_rat c);
816 - Sets `c` to the sum of `a` and integer `b`.
818 ------------
819 <a id="mp_rat_sub_int"></a><pre>
820 mp_result <a href="imrat.h#L147">mp_rat_sub_int</a>(mp_rat a, mp_int b, mp_rat c);
822 - Sets `c` to the difference of `a` less integer `b`.
824 ------------
825 <a id="mp_rat_mul_int"></a><pre>
826 mp_result <a href="imrat.h#L150">mp_rat_mul_int</a>(mp_rat a, mp_int b, mp_rat c);
828 - Sets `c` to the product of `a` and integer `b`.
830 ------------
831 <a id="mp_rat_div_int"></a><pre>
832 mp_result <a href="imrat.h#L154">mp_rat_div_int</a>(mp_rat a, mp_int b, mp_rat c);
834 - Sets `c` to the ratio `a / b` if that ratio is defined.
837 ------------
838 <a id="mp_rat_expt"></a><pre>
839 mp_result <a href="imrat.h#L158">mp_rat_expt</a>(mp_rat a, mp_small b, mp_rat c);
841 - Sets `c` to the value of `a` raised to the `b` power.
844 ------------
845 <a id="mp_rat_compare"></a><pre>
846 int <a href="imrat.h#L161">mp_rat_compare</a>(mp_rat a, mp_rat b);
848 - Returns the comparator of `a` and `b`.
850 ------------
851 <a id="mp_rat_compare_unsigned"></a><pre>
852 int <a href="imrat.h#L165">mp_rat_compare_unsigned</a>(mp_rat a, mp_rat b);
854 - Returns the comparator of the magnitudes of `a` and `b`, disregarding their
855 signs. Neither `a` nor `b` is modified by the comparison.
857 ------------
858 <a id="mp_rat_compare_zero"></a><pre>
859 int <a href="imrat.h#L168">mp_rat_compare_zero</a>(mp_rat r);
861 - Returns the comparator of `r` and zero.
863 ------------
864 <a id="mp_rat_compare_value"></a><pre>
865 int <a href="imrat.h#L172">mp_rat_compare_value</a>(mp_rat r, mp_small n, mp_small d);
867 - Returns the comparator of `r` and the signed ratio `n / d`.
870 ------------
871 <a id="mp_rat_is_integer"></a><pre>
872 bool <a href="imrat.h#L175">mp_rat_is_integer</a>(mp_rat r);
874 - Reports whether `r` is an integer, having canonical denominator 1.
876 ------------
877 <a id="mp_rat_to_ints"></a><pre>
878 mp_result <a href="imrat.h#L180">mp_rat_to_ints</a>(mp_rat r, mp_small *num, mp_small *den);
880 - Reports whether the numerator and denominator of `r` can be represented as
884 ------------
885 <a id="mp_rat_to_string"></a><pre>
886 mp_result <a href="imrat.h#L186">mp_rat_to_string</a>(mp_rat r, mp_size radix, char *str, int limit…
888 - Converts `r` to a zero-terminated string of the format `"n/d"` with `n` and
890 given output buffer `str`. The output of the numerator includes a sign flag
893 ------------
894 <a id="mp_rat_to_decimal"></a><pre>
895 mp_result <a href="imrat.h#L215">mp_rat_to_decimal</a>(mp_rat r, mp_size radix, mp_size prec, mp_ro…
897 - Converts the value of `r` to a string in decimal-point notation with the
903 a decimal value. There are four rounding modes currently supported:
932 ------------
933 <a id="mp_rat_string_len"></a><pre>
934 mp_result <a href="imrat.h#L221">mp_rat_string_len</a>(mp_rat r, mp_size radix);
936 - Reports the minimum number of characters required to represent `r` as a
937 zero-terminated string in the given `radix`.
940 ------------
941 <a id="mp_rat_decimal_len"></a><pre>
942 mp_result <a href="imrat.h#L226">mp_rat_decimal_len</a>(mp_rat r, mp_size radix, mp_size prec);
944 - Reports the length in bytes of the buffer needed to convert `r` using the
948 ------------
949 <a id="mp_rat_read_string"></a><pre>
950 mp_result <a href="imrat.h#L231">mp_rat_read_string</a>(mp_rat r, mp_size radix, const char *str);
952 - Sets `r` to the value represented by a zero-terminated string `str` in the
953 format `"n/d"` including a sign flag. It returns `MP_UNDEF` if the encoded
956 ------------
957 <a id="mp_rat_read_cstring"></a><pre>
958 mp_result <a href="imrat.h#L238">mp_rat_read_cstring</a>(mp_rat r, mp_size radix, const char *str, …
960 - Sets `r` to the value represented by a zero-terminated string `str` in the
961 format `"n/d"` including a sign flag. It returns `MP_UNDEF` if the encoded
965 ------------
966 <a id="mp_rat_read_ustring"></a><pre>
967 mp_result <a href="imrat.h#L252">mp_rat_read_ustring</a>(mp_rat r, mp_size radix, const char *str, …
969 - Sets `r` to the value represented by a zero-terminated string `str` having
974 n/d : ratio format, e.g., "-12/5"
982 ------------
983 <a id="mp_rat_read_decimal"></a><pre>
984 mp_result <a href="imrat.h#L258">mp_rat_read_decimal</a>(mp_rat r, mp_size radix, const char *str);
986 - Sets `r` to the value represented by a zero-terminated string `str` in the
987 format `"z.ffff"` including a sign flag. It returns `MP_UNDEF` if the
990 ------------
991 <a id="mp_rat_read_cdecimal"></a><pre>
992 mp_result <a href="imrat.h#L264">mp_rat_read_cdecimal</a>(mp_rat r, mp_size radix, const char *str,…
994 - Sets `r` to the value represented by a zero-terminated string `str` in the
995 format `"z.ffff"` including a sign flag. It returns `MP_UNDEF` if the
1007 IMath uses a signed magnitude representation for arbitrary precision integers.
1008 The magnitude is represented as an array of radix-R digits in increasing order
1019 mp_digit single; /* single-digit value (see note) */
1030 To avoid interaction with the memory allocator, single-digit values are stored
1037 digits, and rounded up to the nearest `mp_word` boundary. There is a default
1038 minimum precision stored as a static constant default_precision (`imath.c`).
1042 reallocates in order to decrease the size. A simple way to do so explicitly is
1060 example, `mp_int_add(a, a, a)` is legal. Often, this means you must maintain
1063 maintain a conventional structure like this:
1068 Use TEMP(i) to access the ith value (0-indexed). */
1085 If control reaches here via a REQUIRE failure, the code below
1094 and a jump label to handle cleanup. You may only have one `DECLARE_TEMP` and
1098 which are mapped to appropriately-sized types on the host system. The default
1108 Rational numbers are represented using a pair of arbitrary precision integers,
1118 runs all available test vectors. If any tests fail, you will get a line like
1130 % tail +x tests/foo.t | head -1
1133 probably indicates a bug in the library (or at the very least, some assumption
1139 If you build with the preprocessor symbol `DEBUG` defined as a positive
1141 with the value `0xdeadbeefabad1dea`, or as much of it as will fit in a digit,
1146 1. <a name="note1"></a>You can generally use the same variables for both input
1150 2. <a name="note2"></a>Many of the tests for this library were written under
1152 with a smaller type, you may see `MP_RANGE` errors in some of the tests that
1155 tangent is fairly simple-minded.
1163 include a complete description of what went wrong, and if possible, a test
1164 vector for `imtest` and/or a minimal test program that will demonstrate the bug
1179 IMath is Copyright 2002-2009 Michael J. Fromberger
1182 Permission is hereby granted, free of charge, to any person obtaining a copy of
1194 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE