ARM Shanghai IoT Team (Internal) / newMiniTLS-GPL

Fork of MiniTLS-GPL by Donatien Garnier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fp_mod.c Source File

fp_mod.c

00001 /* TomsFastMath, a fast ISO C bignum library.
00002  * 
00003  * This project is meant to fill in where LibTomMath
00004  * falls short.  That is speed ;-)
00005  *
00006  * This project is public domain and free for all purposes.
00007  * 
00008  * Tom St Denis, tomstdenis@gmail.com
00009  */
00010 #include <tfm.h>
00011 
00012 /* c = a mod b, 0 <= c < b  */
00013 int fp_mod(fp_int *a, fp_int *b, fp_int *c)
00014 {
00015    fp_int t;
00016    int    err;
00017 
00018    fp_zero(&t);
00019    if ((err = fp_div(a, b, NULL, &t)) != FP_OKAY) {
00020       return err;
00021    }
00022    if (t.sign != b->sign) {
00023       fp_add(&t, b, c);
00024    } else {
00025       fp_copy(&t, c);
00026   }
00027   return FP_OKAY;
00028 }
00029 
00030 
00031 
00032 /* $Source: /cvs/libtom/tomsfastmath/src/divide/fp_mod.c,v $ */
00033 /* $Revision: 1.1 $ */
00034 /* $Date: 2006/12/31 21:25:53 $ */