updated exp() to handle `n` values which are not powers of 2