From f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Wed, 4 Oct 2017 21:14:00 +1100
Subject: [PATCH] lib/libm: Fix tanhf so that it correctly handles +/- infinity
 args.

---
 lib/libm/math.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/libm/math.c b/lib/libm/math.c
index 984636627..5e00740d1 100644
--- a/lib/libm/math.c
+++ b/lib/libm/math.c
@@ -61,7 +61,12 @@ float log2f(float x) { return logf(x) / (float)_M_LN2; }
 static const float _M_LN10 = 2.30258509299404; // 0x40135d8e
 float log10f(float x) { return logf(x) / (float)_M_LN10; }
 
-float tanhf(float x) { return sinhf(x) / coshf(x); }
+float tanhf(float x) {
+    if (isinf(x)) {
+        return copysignf(1, x);
+    }
+    return sinhf(x) / coshf(x);
+}
 
 /*****************************************************************************/
 /*****************************************************************************/
-- 
GitLab