Loading ...
Sorry, an error occurred while loading the content.
 

Re: vim7: limits of values of vim variables?

Expand Messages
  • A. J. Mechelynck
    ... Under :help variables you will see that Numbers are, in Vim, 32-bit signed integers; IOW, and taking into account the fact that i86 arithmetic is
    Message 1 of 3 , Jan 2, 2006
      Mikolaj Machowski wrote:
      > Hello,
      >
      > After question on comp.editors about power function in Vim I wrote
      > function::
      >
      > function! Power(number, power)
      > if a:power < 0
      > return 0
      > elseif a:power == 0
      > let eval = 1
      > else
      > exe 'let eval = '.repeat(a:number.'*', a:power-1).a:number
      > endif
      > return eval
      > endfunction
      >
      > After calling::
      >
      > echo Power(2,31)
      >
      > And higher values there are some strange results. :help limits mention
      > nothing about that.
      >
      > m.
      >
      >
      >
      >

      Under ":help variables" you will see that Numbers are, in Vim, 32-bit
      signed integers; IOW, and taking into account the fact that i86
      arithmetic is twos-complement, a "Vim number" can range between -2^32
      (inclusive) to +2^32 (exclusive) in steps of one.

      Best regards,
      Tony.
    • Bram Moolenaar
      ... It s just that the size of an int is 32 bits, thus the result doesn t fit. On a system where int is 64 bits it should work. I ll add a remark to the help
      Message 2 of 3 , Jan 2, 2006
        Mikolaj Machowski wrote:

        > After question on comp.editors about power function in Vim I wrote
        > function::
        >
        > function! Power(number, power)
        > if a:power < 0
        > return 0
        > elseif a:power == 0
        > let eval = 1
        > else
        > exe 'let eval = '.repeat(a:number.'*', a:power-1).a:number
        > endif
        > return eval
        > endfunction
        >
        > After calling::
        >
        > echo Power(2,31)
        >
        > And higher values there are some strange results. :help limits mention
        > nothing about that.

        It's just that the size of an int is 32 bits, thus the result doesn't
        fit. On a system where int is 64 bits it should work.

        I'll add a remark to the help on limits. Although it's already
        mentioned at ":help variables".

        --
        hundred-and-one symptoms of being an internet addict:
        2. You kiss your girlfriend's home page.

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://www.ICCF.nl ///
      Your message has been successfully submitted and would be delivered to recipients shortly.