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

Side by Side Diff: fusl/src/math/round.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/rintl.c ('k') | fusl/src/math/roundf.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 #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1
4 #define EPS DBL_EPSILON
5 #elif FLT_EVAL_METHOD==2
6 #define EPS LDBL_EPSILON
7 #endif
8 static const double_t toint = 1/EPS;
9
10 double round(double x)
11 {
12 union {double f; uint64_t i;} u = {x};
13 int e = u.i >> 52 & 0x7ff;
14 double_t y;
15
16 if (e >= 0x3ff+52)
17 return x;
18 if (u.i >> 63)
19 x = -x;
20 if (e < 0x3ff-1) {
21 /* raise inexact if x!=0 */
22 FORCE_EVAL(x + toint);
23 return 0*u.f;
24 }
25 y = x + toint - toint - x;
26 if (y > 0.5)
27 y = y + x - 1;
28 else if (y <= -0.5)
29 y = y + x + 1;
30 else
31 y = y + x;
32 if (u.i >> 63)
33 y = -y;
34 return y;
35 }
OLDNEW
« no previous file with comments | « fusl/src/math/rintl.c ('k') | fusl/src/math/roundf.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698