Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MiniTLS-GPL by
fp_div_2.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 /* b = a/2 */ 00013 void fp_div_2(fp_int * a, fp_int * b) 00014 { 00015 int x, oldused; 00016 00017 oldused = b->used; 00018 b->used = a->used; 00019 { 00020 register fp_digit r, rr, *tmpa, *tmpb; 00021 00022 /* source alias */ 00023 tmpa = a->dp + b->used - 1; 00024 00025 /* dest alias */ 00026 tmpb = b->dp + b->used - 1; 00027 00028 /* carry */ 00029 r = 0; 00030 for (x = b->used - 1; x >= 0; x--) { 00031 /* get the carry for the next iteration */ 00032 rr = *tmpa & 1; 00033 00034 /* shift the current digit, add in carry and store */ 00035 *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1)); 00036 00037 /* forward carry to next iteration */ 00038 r = rr; 00039 } 00040 00041 /* zero excess digits */ 00042 tmpb = b->dp + b->used; 00043 for (x = b->used; x < oldused; x++) { 00044 *tmpb++ = 0; 00045 } 00046 } 00047 b->sign = a->sign; 00048 fp_clamp (b); 00049 } 00050 00051 /* $Source: /cvs/libtom/tomsfastmath/src/bit/fp_div_2.c,v $ */ 00052 /* $Revision: 1.1 $ */ 00053 /* $Date: 2006/12/31 21:25:53 $ */
Generated on Tue Jul 12 2022 19:20:10 by
1.7.2
