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

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

Issue 1714623002: [fusl] clang-format fusl (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: headers too Created 4 years, 10 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
OLDNEW
1 #include <math.h> 1 #include <math.h>
2 #include <stdint.h> 2 #include <stdint.h>
3 3
4 float remquof(float x, float y, int *quo) 4 float remquof(float x, float y, int* quo) {
5 { 5 union {
6 » union {float f; uint32_t i;} ux = {x}, uy = {y}; 6 float f;
7 » int ex = ux.i>>23 & 0xff; 7 uint32_t i;
8 » int ey = uy.i>>23 & 0xff; 8 } ux = {x}, uy = {y};
9 » int sx = ux.i>>31; 9 int ex = ux.i >> 23 & 0xff;
10 » int sy = uy.i>>31; 10 int ey = uy.i >> 23 & 0xff;
11 » uint32_t q; 11 int sx = ux.i >> 31;
12 » uint32_t i; 12 int sy = uy.i >> 31;
13 » uint32_t uxi = ux.i; 13 uint32_t q;
14 uint32_t i;
15 uint32_t uxi = ux.i;
14 16
15 » *quo = 0; 17 *quo = 0;
16 » if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) 18 if (uy.i << 1 == 0 || isnan(y) || ex == 0xff)
17 » » return (x*y)/(x*y); 19 return (x * y) / (x * y);
18 » if (ux.i<<1 == 0) 20 if (ux.i << 1 == 0)
19 » » return x; 21 return x;
20 22
21 » /* normalize x and y */ 23 /* normalize x and y */
22 » if (!ex) { 24 if (!ex) {
23 » » for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1); 25 for (i = uxi << 9; i >> 31 == 0; ex--, i <<= 1)
24 » » uxi <<= -ex + 1; 26 ;
25 » } else { 27 uxi <<= -ex + 1;
26 » » uxi &= -1U >> 9; 28 } else {
27 » » uxi |= 1U << 23; 29 uxi &= -1U >> 9;
28 » } 30 uxi |= 1U << 23;
29 » if (!ey) { 31 }
30 » » for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1); 32 if (!ey) {
31 » » uy.i <<= -ey + 1; 33 for (i = uy.i << 9; i >> 31 == 0; ey--, i <<= 1)
32 » } else { 34 ;
33 » » uy.i &= -1U >> 9; 35 uy.i <<= -ey + 1;
34 » » uy.i |= 1U << 23; 36 } else {
35 » } 37 uy.i &= -1U >> 9;
38 uy.i |= 1U << 23;
39 }
36 40
37 » q = 0; 41 q = 0;
38 » if (ex < ey) { 42 if (ex < ey) {
39 » » if (ex+1 == ey) 43 if (ex + 1 == ey)
40 » » » goto end; 44 goto end;
41 » » return x; 45 return x;
42 » } 46 }
43 47
44 » /* x mod y */ 48 /* x mod y */
45 » for (; ex > ey; ex--) { 49 for (; ex > ey; ex--) {
46 » » i = uxi - uy.i; 50 i = uxi - uy.i;
47 » » if (i >> 31 == 0) { 51 if (i >> 31 == 0) {
48 » » » uxi = i; 52 uxi = i;
49 » » » q++; 53 q++;
50 » » } 54 }
51 » » uxi <<= 1; 55 uxi <<= 1;
52 » » q <<= 1; 56 q <<= 1;
53 » } 57 }
54 » i = uxi - uy.i; 58 i = uxi - uy.i;
55 » if (i >> 31 == 0) { 59 if (i >> 31 == 0) {
56 » » uxi = i; 60 uxi = i;
57 » » q++; 61 q++;
58 » } 62 }
59 » if (uxi == 0) 63 if (uxi == 0)
60 » » ex = -30; 64 ex = -30;
61 » else 65 else
62 » » for (; uxi>>23 == 0; uxi <<= 1, ex--); 66 for (; uxi >> 23 == 0; uxi <<= 1, ex--)
67 ;
63 end: 68 end:
64 » /* scale result and decide between |x| and |x|-|y| */ 69 /* scale result and decide between |x| and |x|-|y| */
65 » if (ex > 0) { 70 if (ex > 0) {
66 » » uxi -= 1U << 23; 71 uxi -= 1U << 23;
67 » » uxi |= (uint32_t)ex << 23; 72 uxi |= (uint32_t)ex << 23;
68 » } else { 73 } else {
69 » » uxi >>= -ex + 1; 74 uxi >>= -ex + 1;
70 » } 75 }
71 » ux.i = uxi; 76 ux.i = uxi;
72 » x = ux.f; 77 x = ux.f;
73 » if (sy) 78 if (sy)
74 » » y = -y; 79 y = -y;
75 » if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { 80 if (ex == ey || (ex + 1 == ey && (2 * x > y || (2 * x == y && q % 2)))) {
76 » » x -= y; 81 x -= y;
77 » » q++; 82 q++;
78 » } 83 }
79 » q &= 0x7fffffff; 84 q &= 0x7fffffff;
80 » *quo = sx^sy ? -(int)q : (int)q; 85 *quo = sx ^ sy ? -(int)q : (int)q;
81 » return sx ? -x : x; 86 return sx ? -x : x;
82 } 87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698