I want to figure out the bit-width of the built-in Number
(integer actually) of Vimscript . In particular, I want to tell whether a 32-bit
or 64-bit
integer is in use. Currently I test whether the maximum constants of both widths can be represented:
let s:INT32_MAX = 2147483647 " 2^31-1
let s:INT64_MAX = 9223372036854775807 " 2^63-1
if s:INT64_MAX > 0
let s:INT_WIDTH = 64
let s:INT_MAX = s:INT64_MAX
else
let s:INT_WIDTH = 32
let s:INT_MAX = s:INT32_MAX
endif
let s:INT_MIN = -s:INT_MAX - 1
This approach has the annoying magic numbers in code. Although it can be replaced by float2nr(pow(2, 31))
, which is exactly s:INT_MAX
above, this requires has('float')
. I wonder if there is any feature that can be tested like has('num64')
. I searched through the :h +feature-list
but found nothing more relevant than OS information like +win32
. Any insight on this question is appreciated.