def tanh(): one_rd = crlibm.log_rd(crlibm.exp_rd(1)) def tanh_rd(x): if x < 0: return -tanh_ru(-x) if x == fpu.infinity: return 1.0 s, c = crlibm.sinh_rd(x), crlibm.cosh_ru(x) if fpu.infinity in (s, c): return one_rd return fpu.down(lambda: s / c) def tanh_ru(x): if x < 0: return -tanh_rd(-x) if x == fpu.infinity: return 1.0 s, c = crlibm.sinh_ru(x), crlibm.cosh_rd(x) if fpu.infinity in (s, c): return 1.0 return fpu.up(lambda: s / c) @monotonic(rd=tanh_rd, ru=tanh_ru) def tanh(c): "Hyberbolic tangent." return tanh
def tanh(): one_rd = crlibm.log_rd(crlibm.exp_rd(1)) def tanh_rd(x): if x < 0: return -tanh_ru(-x) if x == fpu.infinity: return 1.0 s, c = crlibm.sinh_rd(x), crlibm.cosh_ru(x) if fpu.infinity in (s, c): return one_rd return fpu.down(lambda: s/c) def tanh_ru(x): if x < 0: return -tanh_rd(-x) if x == fpu.infinity: return 1.0 s, c = crlibm.sinh_ru(x), crlibm.cosh_rd(x) if fpu.infinity in (s, c): return 1.0 return fpu.up(lambda: s/c) @monotonic(rd=tanh_rd, ru=tanh_ru) def tanh(c): "Hyberbolic tangent." return tanh