Skip to content

Commit f869d6b

Browse files
committed
lib/libm: Fix tanhf so that it correctly handles +/- infinity args.
1 parent 23faf88 commit f869d6b

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/libm/math.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ float log2f(float x) { return logf(x) / (float)_M_LN2; }
6161
static const float _M_LN10 = 2.30258509299404; // 0x40135d8e
6262
float log10f(float x) { return logf(x) / (float)_M_LN10; }
6363

64-
float tanhf(float x) { return sinhf(x) / coshf(x); }
64+
float tanhf(float x) {
65+
if (isinf(x)) {
66+
return copysignf(1, x);
67+
}
68+
return sinhf(x) / coshf(x);
69+
}
6570

6671
/*****************************************************************************/
6772
/*****************************************************************************/

0 commit comments

Comments
 (0)