From e656b9f9ba09460fc2ff2b5faebb6514bb082f4a Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Wed, 28 Dec 2016 00:00:00 +0100 Subject: [PATCH] --- autoload/ingo/math.vim | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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 :