type of number/float in vim script

534 views
Skip to first unread message

mattn

unread,
Dec 26, 2012, 4:08:58 AM12/26/12
to vim...@googlegroups.com
Hi, all

I'm thinking, type of 'number' in vim script must be 64bit. Also 'float' should be 'double' in 2013/2014 or later.
`getfsize()` can't return size of big file over 32bit. And localtime() return 32bit.

I suggest to let us convert types in vim script.

How do you think?

Thanks.

Christian Brabandt

unread,
Dec 26, 2012, 10:15:31 AM12/26/12
to vim...@googlegroups.com
Hi mattn!
Good idea, if this is possible on all architectures where Vim runs.

regards,
Christian
--
Der Kl�gere gibt nach, solange, bis er der dumme ist.

mattn

unread,
Jan 5, 2014, 11:18:14 PM1/5/14
to vim...@googlegroups.com, cbl...@256bit.org
Bram, How about to start implement?
At the first, re-define int64_t or _int64 for vimnumber_T?

mattn

unread,
Jan 6, 2014, 1:34:44 AM1/6/14
to vim...@googlegroups.com, cbl...@256bit.org

Andre Sihera

unread,
Jan 6, 2014, 3:52:50 AM1/6/14
to vim...@googlegroups.com, mattn, cbl...@256bit.org
-
-#if SIZEOF_INT <= 3 /* use long if int is smaller than 32 bits */
-typedef long varnumber_T;
-#else
-typedef int varnumber_T;
-#endif
+typedef int64_t varnumber_T;


In my opinion, this type of change is not acceptable.

If VIM is to be targetted for 32-bit platforms, it should have the option to
run with 32-bit wide types on those platforms for optimal performance.

64-bit wide types on 32-bit platforms cause 64-bit arithmetic emulation
to be performed on ALL integer-based calculations, impacting the speed
of such calculations, be it in-script variable access, loop control, etc.

The typedef should look like this:

#if sizeof(size_t) > 4 /* ANSI C only. need to change to cross-standard
64-bit test */
typedef int64_t varnumber_T;
#else
#if SIZEOF_INT<= 3 /* use long if int is smaller than 32 bits */
typedef long varnumber_T;
#else
typedef int varnumber_T;
#endif
#endif


Use of size_t is the best way in ANSI C to know the width of the system
bus as size_t must be able to reflect the size of the largest possible
addressable memory object (as returned by "malloc()").

Ken Takata

unread,
Jan 21, 2016, 7:48:44 AM1/21/16
to vim_dev, cbl...@256bit.org
Hi mattn and all,

I think that supporting 64-bit Number (even on 32-bit systems) is very useful.
One of the best examples is getfsize() as mattn said. 32-bit Number is too
small to represent a filesize nowadays.


2014/1/6 Mon 15:34:44 UTC+9 mattn wrote:
> https://gist.github.com/mattn/8278843
>
> This is in progress.

I have updated mattn's patch:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/fd966d51f56b69e02d9ebb984355f692b73b2260/num64.patch?at=default&fileviewer=file-view-default

Changes are:

* Sync with the latest codebase.
* VC9 or earlier doesn't have stdint.h, int64_t and uint64_t.
Use __int64 for old Windows compilers.
* Define FEAT_NUM64 in feature.h.
(If someone doesn't like this feature, s/he can disable this by editing
feature.h.)
* Display +/-num64 in :version.
* Add has('num64').
* Adjust the behaviour when dividing by 0. (:help expr-/)
* Adjust the behaviour of float2nr().

I confirmed that getfsize() returned a right value even if the filesize was
over 2 GiB. (My largefile patches are also needed.)
I also confirmed that all existing tests passed.

Of cause, more tests are needed, and documents should be updated.

(See also: [patch] Always use long for vimscript Numbers
https://groups.google.com/d/topic/vim_dev/Ju0DDCqeuMc/discussion )


Regards,
Ken Takata

Tony Mechelynck

unread,
Jan 21, 2016, 10:05:49 AM1/21/16
to vim_dev, Christian Brabandt
Vim differs from some editors such as sed in that it loads the whole
editfile in memory. In a 64-bit Vim, a Number is a 64-bit integer so
no change is required. In a 32-bit Vim, if the filesize doesn't fit in
a 32-bit integer, or even in 'maxmem' (which cannot be more than half
the available system memory), we know that the file won't fit in
memory: we won't be able to edit it. If we need better precision,
which IMHO won't be often, we can get it by parsing a directory
listing (on Unix: let str = system('ls -l ' . expand('filename.ext',
':p')) or similar).

For other purposes, we can exceed 32-bit integer precision in 32-bit
code by using the FPU ("pretending" that our integers are
floating-point numbers). In that case, of course we have to know how
many bits of mantissa are available before we start losing lower-end
digits (lower-end binary digits, for the purists among you).

IIUC, Vim's Float format uses what C calls "double" which on Intel
i686 processors means a 64-bit data item including 53 significant
bits. The "long double" format (maximum hardware precision, with 64
bits _plus_ exponent) is not used by Vim to store data (though the
floating-point hardware uses it for computations, even in Vim). This
"double" format is better than 32-bit but does not reach 64-bit
integers.

Best regards,
Tony.

Ken Takata

unread,
Jan 22, 2016, 7:00:16 AM1/22/16
to vim_dev, cbl...@256bit.org
Hi,

I have updated the patch and divided it into two:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/ec8fa710e76975724c30d0f84c02e1460e5bb705/num64.patch?at=default&fileviewer=file-view-default
https://bitbucket.org/k_takata/vim-ktakata-mq/src/ec8fa710e76975724c30d0f84c02e1460e5bb705/incdec64.patch?at=default&fileviewer=file-view-default

If incdec64.patch is applied, incrementing/decrementing with <C-A>/<C-X> uses
64-bit integer on supported platforms. (Currently, 64-bit int is used on 64-bit
Linux but not on 64-bit Windows.)

Regards,
Ken Takata

Ken Takata

unread,
Jan 24, 2016, 6:13:42 PM1/24/16
to vim_dev, cbl...@256bit.org

Ken Takata

unread,
Jan 29, 2016, 10:57:12 PM1/29/16
to vim_dev, cbl...@256bit.org
Hi,

Here are the updated num64 patches for 7.4.1202 (including docs).
Also available on my bitbucket repository:
https://bitbucket.org/k_takata/vim-ktakata-mq/src

Regards,
Ken Takata

01_num64.patch
02_incdec64.patch
03_num64doc.patch

Bram Moolenaar

unread,
Jan 30, 2016, 7:29:00 AM1/30/16
to Ken Takata, vim_dev, cbl...@256bit.org
Thanks. I'm going to change the function declarations today, this
probably means it's going to change again... After that everything will
be better!

--
hundred-and-one symptoms of being an internet addict:
84. Books in your bookcase bear the names Bongo, WinSock and Inside OLE

/// 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 ///

Ken Takata

unread,
Feb 1, 2016, 8:37:07 AM2/1/16
to vim_dev, ktakat...@gmail.com, cbl...@256bit.org
Hi,

Here are the updated num64 patches.

Regards,
Ken Takata

01_num64.patch
02_incdec64.patch
03_num64doc.patch

Ken Takata

unread,
Feb 24, 2016, 8:10:33 AM2/24/16
to vim_dev, ktakat...@gmail.com
Hi,

I have updated the num64 patch. I have merged the three patches into one again.
This includes the fix of the g<C-G> problem:
https://groups.google.com/d/msg/vim_dev/8epHlRuIAHc/j5I9x9eHEQAJ

Regards,
Ken Takata

num64.patch

Ken Takata

unread,
Mar 28, 2016, 10:24:45 AM3/28/16
to vim_dev, ktakat...@gmail.com
Hi,

2016/2/24 Wed 22:10:33 UTC+9 Ken Takata wrote:
> I have updated the num64 patch. I have merged the three patches into one again.
> This includes the fix of the g<C-G> problem:
> https://groups.google.com/d/msg/vim_dev/8epHlRuIAHc/j5I9x9eHEQAJ

I have updated the num64 patch for 7.4.1665.
Please check the attached patch.

Bram, I'm afraid that you are mistaking some of my patches.
Attached patch is related to the following item from the todo.txt:

L175-176
> Patch to support 64 bit ints for Number. (Ken Takata, 2016 Jan 21)
> Also in update of Feb 24?

The num64 patch is also available from the following URL:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/tip/num64.patch
(I will keep it up to date in the same URL.)


Regards,
Ken Takata

num64.patch

Bram Moolenaar

unread,
Mar 28, 2016, 1:27:40 PM3/28/16
to Ken Takata, vim_dev
Thanks. Hopefully I get to including it one of these days.

--
We are the Borg of GNU GPL. We will assimilate your source code.
Resistance is futile.

Ken Takata

unread,
Apr 4, 2016, 9:38:03 AM4/4/16
to vim_dev, ktakat...@gmail.com
Hi,

2016/3/29 Tue 2:27:40 UTC+9 Bram Moolenaar wrote:
> Ken Takata wrote:
>
> > 2016/2/24 Wed 22:10:33 UTC+9 Ken Takata wrote:
> > > I have updated the num64 patch. I have merged the three patches into one again.
> > > This includes the fix of the g<C-G> problem:
> > > https://groups.google.com/d/msg/vim_dev/8epHlRuIAHc/j5I9x9eHEQAJ
> >
> > I have updated the num64 patch for 7.4.1665.
> > Please check the attached patch.
> >
> > Bram, I'm afraid that you are mistaking some of my patches.
> > Attached patch is related to the following item from the todo.txt:
> >
> > L175-176
> > > Patch to support 64 bit ints for Number. (Ken Takata, 2016 Jan 21)
> > > Also in update of Feb 24?
> >
> > The num64 patch is also available from the following URL:
> > https://bitbucket.org/k_takata/vim-ktakata-mq/src/tip/num64.patch
> > (I will keep it up to date in the same URL.)
>
> Thanks. Hopefully I get to including it one of these days.

I have slightly updated the num64 patch.
I changed to use vim_snprintf() instead of sprintf() when a 64-bit number is
used, and removed VARNUMBER_FMT. I think this makes the source codes a bit
easier to understand. E.g.:

Before:
sprintf((char *)buf, "%"VARNUMBER_FMT"d",
(varnumber_T)varp->vval.v_number);
After:
vim_snprintf((char *)buf, NUMBUFLEN, "%lld",
(varnumber_T)varp->vval.v_number);

Regards,
Ken Takata

num64.patch

Ken Takata

unread,
Jun 14, 2016, 9:20:38 AM6/14/16
to vim_dev, ktakat...@gmail.com
Hi,

I have updated the num64 patch. Now it includes some tests.
While I wrote the tests, I found some bugs, but they are already fixed.
I also added type casts to suppress warnings.
Please check the attached patch. The same patch is also available at:
https://bitbucket.org/k_takata/vim-ktakata-mq/src/tip/num64.patch

Regards,
Ken Takata

num64.patch
Reply all
Reply to author
Forward
0 new messages