1 /* TomsFastMath, a fast ISO C bignum library.
3 * This project is meant to fill in where LibTomMath
4 * falls short. That is speed ;-)
6 * This project is public domain and free for all purposes.
8 * Tom St Denis, tomstdenis@gmail.com
10 #include <tfm_private.h>
13 void fp_sub(fp_int *a, fp_int *b, fp_int *c)
21 /* subtract a negative from a positive, OR */
22 /* subtract a positive from a negative. */
23 /* In either case, ADD their magnitudes, */
24 /* and use the sign of the first number. */
28 /* subtract a positive from a positive, OR */
29 /* subtract a negative from a negative. */
30 /* First, take the difference between their */
31 /* magnitudes, then... */
32 if (fp_cmp_mag (a, b) != FP_LT) {
33 /* Copy the sign from the first */
35 /* The first has a larger or equal magnitude */
38 /* The result has the *opposite* sign from */
39 /* the first number. */
40 c->sign = (sa == FP_ZPOS) ? FP_NEG : FP_ZPOS;
41 /* The second has a larger magnitude */