Big Integers in Vimscript

Magnum by David B├╝rgin is a Vimscript implementation of big integers. Vimscript has two numerical types, Numbers and Floats. Number is 32 bit, so anything larger than about two billion (2,147,483,647) will wrap:

let a=2147483647
echo a
" 2147483647

let a=2147483648
echo a
" -2147483648

Inspired by this limitation, magnum.vim implements algorithms from a book (BigNum math, Syngress, 2006) that support larger integers. This involves implementing methods for mathematical operations and string encoding:

Vim script is not well suited for the task of implementing big integers. It doesn't have suitable unsigned integer types, nor sufficient support for bitwise operations. In the implementation we instead rely a lot on basic arithmetic.

This is probably only interesting to people who are learning Vimscript, but I like the fact the author worked around a Vimscript limitation entirely within Vimscript.

blog comments powered by Disqus