Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: fusl/src/math/tanhf.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fusl/src/math/tanh.c ('k') | fusl/src/math/tanhl.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "libm.h"
2
3 float tanhf(float x)
4 {
5 union {float f; uint32_t i;} u = {.f = x};
6 uint32_t w;
7 int sign;
8 float t;
9
10 /* x = |x| */
11 sign = u.i >> 31;
12 u.i &= 0x7fffffff;
13 x = u.f;
14 w = u.i;
15
16 if (w > 0x3f0c9f54) {
17 /* |x| > log(3)/2 ~= 0.5493 or nan */
18 if (w > 0x41200000) {
19 /* |x| > 10 */
20 t = 1 + 0/x;
21 } else {
22 t = expm1f(2*x);
23 t = 1 - 2/(t+2);
24 }
25 } else if (w > 0x3e82c578) {
26 /* |x| > log(5/3)/2 ~= 0.2554 */
27 t = expm1f(2*x);
28 t = t/(t+2);
29 } else if (w >= 0x00800000) {
30 /* |x| >= 0x1p-126 */
31 t = expm1f(-2*x);
32 t = -t/(t+2);
33 } else {
34 /* |x| is subnormal */
35 FORCE_EVAL(x*x);
36 t = x;
37 }
38 return sign ? -t : t;
39 }
OLDNEW
« no previous file with comments | « fusl/src/math/tanh.c ('k') | fusl/src/math/tanhl.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698