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

Side by Side Diff: fusl/src/math/fmodf.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 fmodf(float x, float y) 4 float fmodf(float x, float y) {
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 » uint32_t sx = ux.i & 0x80000000; 9 int ex = ux.i >> 23 & 0xff;
10 » uint32_t i; 10 int ey = uy.i >> 23 & 0xff;
11 » uint32_t uxi = ux.i; 11 uint32_t sx = ux.i & 0x80000000;
12 uint32_t i;
13 uint32_t uxi = ux.i;
12 14
13 » if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) 15 if (uy.i << 1 == 0 || isnan(y) || ex == 0xff)
14 » » return (x*y)/(x*y); 16 return (x * y) / (x * y);
15 » if (uxi<<1 <= uy.i<<1) { 17 if (uxi << 1 <= uy.i << 1) {
16 » » if (uxi<<1 == uy.i<<1) 18 if (uxi << 1 == uy.i << 1)
17 » » » return 0*x; 19 return 0 * x;
18 » » return x; 20 return x;
19 » } 21 }
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 » /* x mod y */ 41 /* x mod y */
38 » for (; ex > ey; ex--) { 42 for (; ex > ey; ex--) {
39 » » i = uxi - uy.i; 43 i = uxi - uy.i;
40 » » if (i >> 31 == 0) { 44 if (i >> 31 == 0) {
41 » » » if (i == 0) 45 if (i == 0)
42 » » » » return 0*x; 46 return 0 * x;
43 » » » uxi = i; 47 uxi = i;
44 » » } 48 }
45 » » uxi <<= 1; 49 uxi <<= 1;
46 » } 50 }
47 » i = uxi - uy.i; 51 i = uxi - uy.i;
48 » if (i >> 31 == 0) { 52 if (i >> 31 == 0) {
49 » » if (i == 0) 53 if (i == 0)
50 » » » return 0*x; 54 return 0 * x;
51 » » uxi = i; 55 uxi = i;
52 » } 56 }
53 » for (; uxi>>23 == 0; uxi <<= 1, ex--); 57 for (; uxi >> 23 == 0; uxi <<= 1, ex--)
58 ;
54 59
55 » /* scale result up */ 60 /* scale result up */
56 » if (ex > 0) { 61 if (ex > 0) {
57 » » uxi -= 1U << 23; 62 uxi -= 1U << 23;
58 » » uxi |= (uint32_t)ex << 23; 63 uxi |= (uint32_t)ex << 23;
59 » } else { 64 } else {
60 » » uxi >>= -ex + 1; 65 uxi >>= -ex + 1;
61 » } 66 }
62 » uxi |= sx; 67 uxi |= sx;
63 » ux.i = uxi; 68 ux.i = uxi;
64 » return ux.f; 69 return ux.f;
65 } 70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698