a subroutine to calculate power