fixed tanh to not return NaN for input values outside the range [-40, 40]