Fix handling negative screen filters values
This commit is contained in:
parent
ef1072f996
commit
dc7edbd44f
@ -142,21 +142,47 @@ static int parseDecIntOption(s64 *out, const char *val, s64 minval, s64 maxval)
|
|||||||
|
|
||||||
static int parseDecFloatOption(s64 *out, const char *val, s64 minval, s64 maxval)
|
static int parseDecFloatOption(s64 *out, const char *val, s64 minval, s64 maxval)
|
||||||
{
|
{
|
||||||
char *point = strchrnul(val, '.');
|
s64 sign = 1;// intPart < 0 ? -1 : 1;
|
||||||
if (point == val) {
|
|
||||||
|
switch (val[0]) {
|
||||||
|
case '\0':
|
||||||
|
return -1;
|
||||||
|
case '+':
|
||||||
|
++val;
|
||||||
|
break;
|
||||||
|
case '-':
|
||||||
|
sign = -1;
|
||||||
|
++val;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reject "-" and "+"
|
||||||
|
if (val[0] == '\0') {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *point = strchrnul(val, '.');
|
||||||
|
|
||||||
// Parse integer part, then fractional part
|
// Parse integer part, then fractional part
|
||||||
s64 intPart = 0;
|
s64 intPart = 0;
|
||||||
s64 fracPart = 0;
|
s64 fracPart = 0;
|
||||||
int rc = parseDecIntOptionImpl(&intPart, val, point - val, INT64_MIN, INT64_MAX);
|
int rc = 0;
|
||||||
|
|
||||||
|
if (point == val) {
|
||||||
|
// e.g. -.5
|
||||||
|
if (val[1] == '\0')
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rc = parseDecIntOptionImpl(&intPart, val, point - val, INT64_MIN, INT64_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
s64 sign = intPart < 0 ? -1 : 1;
|
|
||||||
s64 intPartAbs = sign == -1 ? -intPart : intPart;
|
s64 intPartAbs = sign == -1 ? -intPart : intPart;
|
||||||
s64 res = 0;
|
s64 res = 0;
|
||||||
bool of = __builtin_mul_overflow(intPartAbs, FLOAT_CONV_MULT, &res);
|
bool of = __builtin_mul_overflow(intPartAbs, FLOAT_CONV_MULT, &res);
|
||||||
|
@ -179,8 +179,8 @@ int floatToString(char *out, float f, u32 precision, bool pad)
|
|||||||
|
|
||||||
u64 mult = pow10[precision];
|
u64 mult = pow10[precision];
|
||||||
double f2 = fabs((double)f) * mult + 0.5;
|
double f2 = fabs((double)f) * mult + 0.5;
|
||||||
const char *sign = f2 >= 0.0f ? "" : "-";
|
|
||||||
u64 f3 = (u64)f2;
|
u64 f3 = (u64)f2;
|
||||||
|
const char *sign = (f >= 0.0f || f3 == 0) ? "" : "-";
|
||||||
|
|
||||||
u64 intPart = f3 / mult;
|
u64 intPart = f3 / mult;
|
||||||
u64 fracPart = f3 % mult;
|
u64 fracPart = f3 % mult;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user