mirror of
https://github.com/pnx/m16vm
synced 2026-06-16 03:44:55 +02:00
as/lexer/number.c: cleaning up lexer_read_num_dec() abit, skipping goto.
This commit is contained in:
parent
969c092e6f
commit
502f284ebd
1 changed files with 9 additions and 8 deletions
|
|
@ -52,7 +52,7 @@ overflow:
|
|||
|
||||
int lexer_read_num_dec(FILE *fp, int neg, int *out) {
|
||||
|
||||
int c, val = 0;
|
||||
int c, val = 0, oflow = 0;
|
||||
|
||||
while((c = fgetc(fp)) != EOF) {
|
||||
if (!lexer_is_num(c)) {
|
||||
|
|
@ -64,14 +64,15 @@ int lexer_read_num_dec(FILE *fp, int neg, int *out) {
|
|||
// Cool trick here.
|
||||
// because the range is -128 (0x80) to +127 (0x7F)
|
||||
// We can do 0x80 - 1 if it is NOT a negative number.
|
||||
if (val > (0x80 - !neg))
|
||||
goto overflow;
|
||||
if (val > (0x80 - !neg)) {
|
||||
// Truncate value.
|
||||
val = 0x80 - !neg;
|
||||
oflow = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*out = neg ? -1 * val : val;
|
||||
return 0;
|
||||
|
||||
overflow:
|
||||
*out = neg ? -1 * 0x80 : 0x7F;
|
||||
return -1;
|
||||
return -oflow;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue