Created safe_log and safe_atan2 funcs for prism

Safe versions of atan2 and log that can handle the limits used in the
prism codes (log(0) and correct the sign of tangents).