Created
March 28, 2015 10:03
-
-
Save aomoriringo/fbdea06d847a8cdf42f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let s:name = 'World' | |
echo "\nHello" . s:name | |
function! Isdigit(str) | |
return match(a:str, '^[+-]\?\d\+$') != -1 | |
endfunction | |
let g:bigint = {'num': [], 'sign': 1} | |
let g:nodeMaxDigit = 8 | |
let g:nodeMaxNum = 100000000 | |
function! StringToBigint(str) | |
if Isdigit(a:str) != 1 | |
throw 'is not digit: '.a:str | |
endif | |
let bigint = deepcopy(g:bigint) | |
let bigint.sign = (a:str[0] == "-") ? -1 : 1 | |
if match(a:str, '^[+-]') != -1 | |
let l:str = a:str[1:] | |
else | |
let l:str = a:str | |
endif | |
let l:strlen = len(l:str) | |
let l:nodes = ((l:strlen-1)/g:nodeMaxDigit)+1 | |
let l:head_node_len = l:strlen % g:nodeMaxDigit | |
if l:head_node_len != 0 | |
call add(bigint.num, l:str[: l:head_node_len-1]) | |
endif | |
let l:tail_nodes = split(l:str[l:head_node_len :], '.\{' . g:nodeMaxDigit . '}\zs') | |
let l:bigint.num = map(l:bigint.num + l:tail_nodes, 'str2nr(v:val)') | |
return l:bigint | |
endfunction | |
function! BigintToString(bigint) | |
let l:str = '' | |
let l:str .= string(a:bigint.num[0]) | |
for node in a:bigint.num[1:] | |
let l:str .= printf('%0'.g:nodeMaxDigit.'d', node) | |
endfor | |
if a:bigint.sign == -1 | |
let l:str = '-' .l:str | |
endif | |
return l:str | |
endfunction | |
" a > b: return 1 | |
" a = b: return 0 | |
" a < b: return -1 | |
function! Bigcompare(a,b) | |
if a:a.sign != a:b.sign | |
return (a:a.sign == 1) ? 1 : -1 | |
endif | |
if len(a:a.num) | |
endfunction | |
function! Bigadd(a,b) | |
endfunction | |
function! Bigshift(a,num) | |
endfunction | |
function! Bigsub(a,b) | |
endfunction | |
function! Bigmul(a,b) | |
endfunction | |
function! Bigdiv(a,b) | |
endfunction | |
function! Bigmod(a,b) | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment