refactor: format casting of negative number better (#26482)

This commit is contained in:
zeertzjq 2023-12-09 11:36:11 +08:00 committed by GitHub
parent c651fb3042
commit 2ebd328a79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 9 deletions

View File

@ -5029,7 +5029,7 @@ size_t string2float(const char *const text, float_T *const ret_value)
return 3;
}
if (STRNICMP(text, "-inf", 3) == 0) {
*ret_value = (float_T) - INFINITY;
*ret_value = (float_T)(-INFINITY);
return 4;
}
if (STRNICMP(text, "nan", 3) == 0) {

View File

@ -2171,7 +2171,7 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return;
}
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
if (f <= (float_T)(-VARNUMBER_MAX) + DBL_EPSILON) {
rettv->vval.v_number = -VARNUMBER_MAX;
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
rettv->vval.v_number = VARNUMBER_MAX;

View File

@ -1254,7 +1254,7 @@ handle_T nlua_pop_handle(lua_State *lstate, Error *err)
handle_T ret;
if (lua_type(lstate, -1) != LUA_TNUMBER) {
api_set_error(err, kErrorTypeValidation, "Expected Lua number");
ret = (handle_T) - 1;
ret = (handle_T)(-1);
} else {
ret = (handle_T)lua_tonumber(lstate, -1);
}

View File

@ -1288,12 +1288,12 @@ void mark_adjust_buf(buf_T *buf, linenr_T line1, linenr_T line2, linenr_T amount
if (posp->lnum == lnum && posp->col >= mincol) { \
posp->lnum += lnum_amount; \
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
if (col_amount < 0 && posp->col <= (colnr_T) - col_amount) { \
if (col_amount < 0 && posp->col <= -col_amount) { \
posp->col = 0; \
} else if (posp->col < spaces_removed) { \
posp->col = (int)col_amount + spaces_removed; \
posp->col = col_amount + spaces_removed; \
} else { \
posp->col += (colnr_T)col_amount; \
posp->col += col_amount; \
} \
} \
}

View File

@ -4630,13 +4630,13 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if (!pre) {
if (subtract) {
if (n > oldn) {
n = 1 + (n ^ (uvarnumber_T) - 1);
n = 1 + (n ^ (uvarnumber_T)(-1));
negative ^= true;
}
} else {
// add
if (n < oldn) {
n = (n ^ (uvarnumber_T) - 1);
n = (n ^ (uvarnumber_T)(-1));
negative ^= true;
}
}

View File

@ -678,7 +678,7 @@ void auto_format(bool trailblank, bool prev_line)
// Do the formatting and restore the cursor position. "saved_cursor" will
// be adjusted for the text formatting.
saved_cursor = pos;
format_lines((linenr_T) - 1, false);
format_lines(-1, false);
curwin->w_cursor = saved_cursor;
saved_cursor.lnum = 0;