[patch] Always use long for vimscript Numbers

75 views
Skip to first unread message

James McCoy

unread,
Jun 13, 2015, 1:00:19 AM6/13/15
to Bram Moolenaar, vim...@googlegroups.com
According to “:help Number”, one would expect to be able to work with
64-bit numbers in vimscript, especially if you're on a 64-bit OS.

However, Vim only uses a long to represent vimscript numbers if
sizeof(int) isn't at least 32-bits. The attached patch removes the
sizeof(int) check and always uses long so the user always gets the
native max integer size available.

Cheers,
--
James
GPG Key: 4096R/331BA3DB 2011-12-05 James McCoy <jame...@jamessan.com>
long-Number.diff
signature.asc

Bram Moolenaar

unread,
Jun 13, 2015, 8:58:09 AM6/13/15
to James McCoy, vim...@googlegroups.com

James McCoy wrote:

> According to “:help Number”, one would expect to be able to work with
> 64-bit numbers in vimscript, especially if you're on a 64-bit OS.
>
> However, Vim only uses a long to represent vimscript numbers if
> sizeof(int) isn't at least 32-bits. The attached patch removes the
> sizeof(int) check and always uses long so the user always gets the
> native max integer size available.

For a long time, Vim script numbers were intentionally 32 bits. Because
that should work everywhere. Using 64 bits in some places would cause
some scripts to fail on other machines.

Now that 64 bits is very common, we should change that and use 64 bits
where possible. Also because some machines now have 64 bit ints, thus
this may be used already anyway.

Your patch doesn't work for MS-Windows, where long is still 32 bits.
We should do some more work and use the type for 64 bit where possible.

We also need to update the documentation. We should also make it
possible to test whether the Number type is 32 or 64 bits, so that
scripts can give an error if it's not sufficient.

--
From "know your smileys":
<|-) Chinese
<|-( Chinese and doesn't like these kind of jokes

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages