diff --git a/autoload/ingo/math.vim b/autoload/ingo/math.vim index dfc7289..d3c5d23 100644 --- a/autoload/ingo/math.vim +++ b/autoload/ingo/math.vim @@ -32,4 +32,31 @@ function! ingo#math#BitsRequired( num ) return l:bitCnt endfunction +"****************************************************************************** +"* PURPOSE: +" Return the power of a:x to the exponent a:y as a Number. +"* ASSUMPTIONS / PRECONDITIONS: +" None. +"* EFFECTS / POSTCONDITIONS: +" None. +"* INPUTS: +" a:x Number. +" a:y Exponent. +"* RETURN VALUES: +" Number. +"****************************************************************************** +if exists('*pow') + function! ingo#math#PowNr( x, y ) + return float2nr(pow(a:x, a:y)) + endfunction +else + function! ingo#math#PowNr( x, y ) + let l:r = a:x + for l:i in range(a:y - 1) + let l:r = l:r * a:x + endfor + return l:r + endfunction +endif + " vim: set ts=8 sts=4 sw=4 noexpandtab ff=unix fdm=syntax :