improved pow logic to accept negative numbers and deal correctly with NaN situations