This question already has an answer here:

Related to Why does vim allow to divide by zero, what's going on here?

:let a=-42/0
:echo a

:let b=a - 1
:echo b

marked as duplicate by statox, Christian Brabandt, Martin Tournoij Sep 3 '15 at 20:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @Nobe4's answer on the linked question is more than sufficient to answer this question, so this question is now a duplicate. – Jacob Krall Sep 3 '15 at 14:42

It is because vim represents the signed integers on 32 bits which makes that -2147483648 actually is the smallest number in Vim and not -2147483647 as you could think.

let foo = -2147483647
echo foo - 1
=> -2147483648

let foo = -2147483648
echo foo - 1
=> 2147483647

On 32 bits the max value of an integer is 2^31-1 when the min value is -2^31. For an explanation of this different values see this wiki page about the two complement in the representation of signed integers.

  • See my edition on the linked question :) : -2147483648 is used for representing NaN – nobe4 Sep 3 '15 at 6:31
  • @statox: this answer does not explain why -X/0 is -2147483647 instead of -2147483648. – Jacob Krall Sep 3 '15 at 14:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.