diff options
author | Damien George <damien.p.george@gmail.com> | 2017-10-04 21:14:00 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-10-04 21:14:00 +1100 |
commit | f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c (patch) | |
tree | 842b00c2cc3d10f4bbee290f29d3f1bfc29f5762 /lib/libm/math.c | |
parent | 23faf88cab10a216eb24a30b4f33edd17183522c (diff) | |
download | micropython-f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c.tar.gz micropython-f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c.zip |
lib/libm: Fix tanhf so that it correctly handles +/- infinity args.
Diffstat (limited to 'lib/libm/math.c')
-rw-r--r-- | lib/libm/math.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/libm/math.c b/lib/libm/math.c index 984636627c..5e00740d10 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); +} /*****************************************************************************/ /*****************************************************************************/ |