mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
refactor: format casting of negative number better (#26482)
This commit is contained in:
parent
c651fb3042
commit
2ebd328a79
@ -5029,7 +5029,7 @@ size_t string2float(const char *const text, float_T *const ret_value)
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
if (STRNICMP(text, "-inf", 3) == 0) {
|
if (STRNICMP(text, "-inf", 3) == 0) {
|
||||||
*ret_value = (float_T) - INFINITY;
|
*ret_value = (float_T)(-INFINITY);
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
if (STRNICMP(text, "nan", 3) == 0) {
|
if (STRNICMP(text, "nan", 3) == 0) {
|
||||||
|
@ -2171,7 +2171,7 @@ static void f_float2nr(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f <= (float_T) - VARNUMBER_MAX + DBL_EPSILON) {
|
if (f <= (float_T)(-VARNUMBER_MAX) + DBL_EPSILON) {
|
||||||
rettv->vval.v_number = -VARNUMBER_MAX;
|
rettv->vval.v_number = -VARNUMBER_MAX;
|
||||||
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
|
} else if (f >= (float_T)VARNUMBER_MAX - DBL_EPSILON) {
|
||||||
rettv->vval.v_number = VARNUMBER_MAX;
|
rettv->vval.v_number = VARNUMBER_MAX;
|
||||||
|
@ -1254,7 +1254,7 @@ handle_T nlua_pop_handle(lua_State *lstate, Error *err)
|
|||||||
handle_T ret;
|
handle_T ret;
|
||||||
if (lua_type(lstate, -1) != LUA_TNUMBER) {
|
if (lua_type(lstate, -1) != LUA_TNUMBER) {
|
||||||
api_set_error(err, kErrorTypeValidation, "Expected Lua number");
|
api_set_error(err, kErrorTypeValidation, "Expected Lua number");
|
||||||
ret = (handle_T) - 1;
|
ret = (handle_T)(-1);
|
||||||
} else {
|
} else {
|
||||||
ret = (handle_T)lua_tonumber(lstate, -1);
|
ret = (handle_T)lua_tonumber(lstate, -1);
|
||||||
}
|
}
|
||||||
|
@ -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) { \
|
if (posp->lnum == lnum && posp->col >= mincol) { \
|
||||||
posp->lnum += lnum_amount; \
|
posp->lnum += lnum_amount; \
|
||||||
assert(col_amount > INT_MIN && col_amount <= INT_MAX); \
|
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; \
|
posp->col = 0; \
|
||||||
} else if (posp->col < spaces_removed) { \
|
} else if (posp->col < spaces_removed) { \
|
||||||
posp->col = (int)col_amount + spaces_removed; \
|
posp->col = col_amount + spaces_removed; \
|
||||||
} else { \
|
} else { \
|
||||||
posp->col += (colnr_T)col_amount; \
|
posp->col += col_amount; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
@ -4630,13 +4630,13 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
|
|||||||
if (!pre) {
|
if (!pre) {
|
||||||
if (subtract) {
|
if (subtract) {
|
||||||
if (n > oldn) {
|
if (n > oldn) {
|
||||||
n = 1 + (n ^ (uvarnumber_T) - 1);
|
n = 1 + (n ^ (uvarnumber_T)(-1));
|
||||||
negative ^= true;
|
negative ^= true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// add
|
// add
|
||||||
if (n < oldn) {
|
if (n < oldn) {
|
||||||
n = (n ^ (uvarnumber_T) - 1);
|
n = (n ^ (uvarnumber_T)(-1));
|
||||||
negative ^= true;
|
negative ^= true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -678,7 +678,7 @@ void auto_format(bool trailblank, bool prev_line)
|
|||||||
// Do the formatting and restore the cursor position. "saved_cursor" will
|
// Do the formatting and restore the cursor position. "saved_cursor" will
|
||||||
// be adjusted for the text formatting.
|
// be adjusted for the text formatting.
|
||||||
saved_cursor = pos;
|
saved_cursor = pos;
|
||||||
format_lines((linenr_T) - 1, false);
|
format_lines(-1, false);
|
||||||
curwin->w_cursor = saved_cursor;
|
curwin->w_cursor = saved_cursor;
|
||||||
saved_cursor.lnum = 0;
|
saved_cursor.lnum = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user