update fpcalc to recognize 0x, x, or just hex

This commit is contained in:
James Stine 2024-10-01 15:46:35 -05:00
parent df2dd3f887
commit bcd6f3da16

View File

@ -224,13 +224,13 @@ __uint128_t strtoul128(char *num, int base) {
}
__uint128_t parseNum(char *num) {
// uint64_t result;
__uint128_t result;
__uint128_t result = 0;
// Ensure input starts with "0x" or "x"
if (!(num[0] == '0' && num[1] == 'x') && !(num[0] == 'x')) {
printf("Error: Input must start with '0x' or 'x'\n");
exit(1);
// Ensure input is in correct form
if (num[0] == '0' && num[1] == 'x') {
num += 2; // Skip "0x"
} else if (num[0] == 'x') {
num += 1; // Skip "x"
}
int size; // size of operands in bytes (2= half, 4=single, 8 = double)
@ -251,12 +251,6 @@ __uint128_t parseNum(char *num) {
opSize = size;
}
// Add to handle either input preference
// Strip the "x" or "0x" prefixes if present
if (num[0] == 'x' || (num[0] == '0' && num[1] == 'x')) {
num += (num[0] == 'x') ? 1 : 2;
}
if (strlen(num) <= 16) {
result = (__uint128_t)strtoull(num, NULL, 16);
}
@ -302,8 +296,7 @@ char parseRound(char *rnd) {
}
}
int main(int argc, char *argv[])
{
int main(int argc, char *argv[]) {
//uint64_t xn, yn, zn;
__uint128_t xn, yn, zn;
char op1, op2;