|
@@ -124,19 +124,19 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o,
|
|
|
case STRSCAN_INT:
|
|
|
if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg &&
|
|
|
!(x == 0 && neg)) {
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
|
|
|
return STRSCAN_INT; /* Fast path for 32 bit integers. */
|
|
|
}
|
|
|
if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
|
|
|
/* fallthrough */
|
|
|
case STRSCAN_U32:
|
|
|
if (dig > 8) return STRSCAN_ERROR;
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
|
|
|
return STRSCAN_U32;
|
|
|
case STRSCAN_I64:
|
|
|
case STRSCAN_U64:
|
|
|
if (dig > 16) return STRSCAN_ERROR;
|
|
|
- o->u64 = neg ? (uint64_t)-(int64_t)x : x;
|
|
|
+ o->u64 = neg ? ~x+1u : x;
|
|
|
return fmt;
|
|
|
default:
|
|
|
break;
|
|
@@ -168,12 +168,12 @@ static StrScanFmt strscan_oct(const uint8_t *p, TValue *o,
|
|
|
/* fallthrough */
|
|
|
case STRSCAN_U32:
|
|
|
if ((x >> 32)) return STRSCAN_ERROR;
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~(uint32_t)x+1u) : (int32_t)x;
|
|
|
break;
|
|
|
default:
|
|
|
case STRSCAN_I64:
|
|
|
case STRSCAN_U64:
|
|
|
- o->u64 = neg ? (uint64_t)-(int64_t)x : x;
|
|
|
+ o->u64 = neg ? ~x+1u : x;
|
|
|
break;
|
|
|
}
|
|
|
return fmt;
|
|
@@ -229,18 +229,18 @@ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o,
|
|
|
switch (fmt) {
|
|
|
case STRSCAN_INT:
|
|
|
if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
|
|
|
return STRSCAN_INT; /* Fast path for 32 bit integers. */
|
|
|
}
|
|
|
if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }
|
|
|
/* fallthrough */
|
|
|
case STRSCAN_U32:
|
|
|
if ((x >> 32) != 0) return STRSCAN_ERROR;
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
|
|
|
return STRSCAN_U32;
|
|
|
case STRSCAN_I64:
|
|
|
case STRSCAN_U64:
|
|
|
- o->u64 = neg ? (uint64_t)-(int64_t)x : x;
|
|
|
+ o->u64 = neg ? ~x+1u : x;
|
|
|
return fmt;
|
|
|
default:
|
|
|
plainnumber: /* Fast path for plain numbers < 2^63. */
|
|
@@ -418,7 +418,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt)
|
|
|
if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR;
|
|
|
p++;
|
|
|
}
|
|
|
- ex += negx ? -(int32_t)xx : (int32_t)xx;
|
|
|
+ ex += negx ? (int32_t)(~xx+1u) : (int32_t)xx;
|
|
|
}
|
|
|
|
|
|
/* Parse suffix. */
|
|
@@ -456,7 +456,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, TValue *o, uint32_t opt)
|
|
|
o->n = -0.0;
|
|
|
return STRSCAN_NUM;
|
|
|
} else {
|
|
|
- o->i = neg ? -(int32_t)x : (int32_t)x;
|
|
|
+ o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
|
|
|
return STRSCAN_INT;
|
|
|
}
|
|
|
}
|