mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-21 10:26:06 +03:00
fixed a bigint issue
git-svn-id: svn://svn.code.sf.net/p/axtls/code/trunk@149 9a5d90b5-6617-0410-8a86-bb477d3ed2e3
This commit is contained in:
parent
bf4238d4e7
commit
d02abde904
@ -517,7 +517,7 @@ static bigint *bi_int_divide(BI_CTX *ctx, bigint *biR, comp denom)
|
||||
r = (r<<COMP_BIT_SIZE) + biR->comps[i];
|
||||
biR->comps[i] = (comp)(r / denom);
|
||||
r %= denom;
|
||||
} while (--i != 0);
|
||||
} while (--i >= 0);
|
||||
|
||||
return trim(biR);
|
||||
}
|
||||
@ -947,6 +947,7 @@ static bigint *regular_square(BI_CTX *ctx, bigint *bi)
|
||||
for (j = i+1; j < t; j++)
|
||||
{
|
||||
long_comp xx = (long_comp)x[i]*x[j];
|
||||
long_comp xx2 = 2*xx;
|
||||
long_comp blob = (long_comp)w[i+j]+carry;
|
||||
|
||||
if (u) /* previous overflow */
|
||||
@ -954,13 +955,16 @@ static bigint *regular_square(BI_CTX *ctx, bigint *bi)
|
||||
blob += COMP_RADIX;
|
||||
}
|
||||
|
||||
|
||||
u = 0;
|
||||
if (xx & COMP_BIG_MSB) /* check for overflow */
|
||||
tmp = xx2 + blob;
|
||||
|
||||
/* check for overflow */
|
||||
if ((COMP_MAX-xx) < xx || (COMP_MAX-xx2) < blob)
|
||||
{
|
||||
u = 1;
|
||||
}
|
||||
|
||||
tmp = 2*xx + blob;
|
||||
w[i+j] = (comp)tmp;
|
||||
carry = (comp)(tmp >> COMP_BIT_SIZE);
|
||||
}
|
||||
|
@ -44,10 +44,10 @@
|
||||
/* Architecture specific functions for big ints */
|
||||
#ifdef WIN32
|
||||
#define COMP_RADIX 4294967296i64
|
||||
#define COMP_BIG_MSB 0x8000000000000000i64
|
||||
#define COMP_MAX 0xFFFFFFFFFFFFFFFFi64
|
||||
#else
|
||||
#define COMP_RADIX 4294967296ULL /**< Max component + 1 */
|
||||
#define COMP_BIG_MSB 0x8000000000000000ULL /**< (Max dbl comp + 1)/ 2 */
|
||||
#define COMP_MAX 0xFFFFFFFFFFFFFFFFULL/**< (Max dbl comp -1) */
|
||||
#endif
|
||||
#define COMP_BIT_SIZE 32 /**< Number of bits in a component. */
|
||||
#define COMP_BYTE_SIZE 4 /**< Number of bytes in a component. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user