forked from ibphoenix/tomsfastmath
fp_read_radix: port modifications from libtommath
This commit is contained in:
parent
74df3d9970
commit
60cf64919f
@ -14,6 +14,9 @@ int fp_read_radix(fp_int *a, char *str, int radix)
|
|||||||
int y, neg;
|
int y, neg;
|
||||||
char ch;
|
char ch;
|
||||||
|
|
||||||
|
/* set the integer to the default of zero */
|
||||||
|
fp_zero (a);
|
||||||
|
|
||||||
/* make sure the radix is ok */
|
/* make sure the radix is ok */
|
||||||
if (radix < 2 || radix > 64) {
|
if (radix < 2 || radix > 64) {
|
||||||
return FP_VAL;
|
return FP_VAL;
|
||||||
@ -29,16 +32,13 @@ int fp_read_radix(fp_int *a, char *str, int radix)
|
|||||||
neg = FP_ZPOS;
|
neg = FP_ZPOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the integer to the default of zero */
|
|
||||||
fp_zero (a);
|
|
||||||
|
|
||||||
/* process each digit of the string */
|
/* process each digit of the string */
|
||||||
while (*str) {
|
while (*str) {
|
||||||
/* if the radix < 36 the conversion is case insensitive
|
/* if the radix < 36 the conversion is case insensitive
|
||||||
* this allows numbers like 1AB and 1ab to represent the same value
|
* this allows numbers like 1AB and 1ab to represent the same value
|
||||||
* [e.g. in hex]
|
* [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++) {
|
for (y = 0; y < 64; y++) {
|
||||||
if (ch == fp_s_rmap[y]) {
|
if (ch == fp_s_rmap[y]) {
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user