fp_read_radix: port modifications from libtommath
This commit is contained in:
parent
74df3d9970
commit
60cf64919f
@ -1,10 +1,10 @@
|
||||
/* TomsFastMath, a fast ISO C bignum library.
|
||||
*
|
||||
*
|
||||
* This project is meant to fill in where LibTomMath
|
||||
* falls short. That is speed ;-)
|
||||
*
|
||||
* This project is public domain and free for all purposes.
|
||||
*
|
||||
*
|
||||
* Tom St Denis, tomstdenis@gmail.com
|
||||
*/
|
||||
#include <tfm.h>
|
||||
@ -14,6 +14,9 @@ int fp_read_radix(fp_int *a, char *str, int radix)
|
||||
int y, neg;
|
||||
char ch;
|
||||
|
||||
/* set the integer to the default of zero */
|
||||
fp_zero (a);
|
||||
|
||||
/* make sure the radix is ok */
|
||||
if (radix < 2 || radix > 64) {
|
||||
return FP_VAL;
|
||||
@ -29,16 +32,13 @@ int fp_read_radix(fp_int *a, char *str, int radix)
|
||||
neg = FP_ZPOS;
|
||||
}
|
||||
|
||||
/* set the integer to the default of zero */
|
||||
fp_zero (a);
|
||||
|
||||
/* process each digit of the string */
|
||||
while (*str) {
|
||||
/* if the radix < 36 the conversion is case insensitive
|
||||
* this allows numbers like 1AB and 1ab to represent the same value
|
||||
* [e.g. in hex]
|
||||
*/
|
||||
ch = (char) ((radix < 36) ? toupper ((int)*str) : *str);
|
||||
ch = (char) ((radix <= 36) ? toupper ((int)*str) : *str);
|
||||
for (y = 0; y < 64; y++) {
|
||||
if (ch == fp_s_rmap[y]) {
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user