mirror of
https://github.com/openhwgroup/cvw
synced 2025-02-11 06:05:49 +00:00
update fpcalc to recognize 0x, x, or just hex
This commit is contained in:
parent
df2dd3f887
commit
bcd6f3da16
@ -224,13 +224,13 @@ __uint128_t strtoul128(char *num, int base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__uint128_t parseNum(char *num) {
|
__uint128_t parseNum(char *num) {
|
||||||
// uint64_t result;
|
__uint128_t result = 0;
|
||||||
__uint128_t result;
|
|
||||||
|
|
||||||
// Ensure input starts with "0x" or "x"
|
// Ensure input is in correct form
|
||||||
if (!(num[0] == '0' && num[1] == 'x') && !(num[0] == 'x')) {
|
if (num[0] == '0' && num[1] == 'x') {
|
||||||
printf("Error: Input must start with '0x' or 'x'\n");
|
num += 2; // Skip "0x"
|
||||||
exit(1);
|
} else if (num[0] == 'x') {
|
||||||
|
num += 1; // Skip "x"
|
||||||
}
|
}
|
||||||
|
|
||||||
int size; // size of operands in bytes (2= half, 4=single, 8 = double)
|
int size; // size of operands in bytes (2= half, 4=single, 8 = double)
|
||||||
@ -251,12 +251,6 @@ __uint128_t parseNum(char *num) {
|
|||||||
opSize = size;
|
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) {
|
if (strlen(num) <= 16) {
|
||||||
result = (__uint128_t)strtoull(num, NULL, 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;
|
//uint64_t xn, yn, zn;
|
||||||
__uint128_t xn, yn, zn;
|
__uint128_t xn, yn, zn;
|
||||||
char op1, op2;
|
char op1, op2;
|
||||||
|
Loading…
Reference in New Issue
Block a user