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

Unified Diff: fusl/src/math/fmod.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 side-by-side diff with in-line comments
Download patch
Index: fusl/src/math/fmod.c
diff --git a/fusl/src/math/fmod.c b/fusl/src/math/fmod.c
index 6849722bac50e477b9210f57f0271dcdabd8ae0c..7caea97dc2a88d6e8545f25bb216f3f538fd3c20 100644
--- a/fusl/src/math/fmod.c
+++ b/fusl/src/math/fmod.c
@@ -1,68 +1,73 @@
#include <math.h>
#include <stdint.h>
-double fmod(double x, double y)
-{
- union {double f; uint64_t i;} ux = {x}, uy = {y};
- int ex = ux.i>>52 & 0x7ff;
- int ey = uy.i>>52 & 0x7ff;
- int sx = ux.i>>63;
- uint64_t i;
+double fmod(double x, double y) {
+ union {
+ double f;
+ uint64_t i;
+ } ux = {x}, uy = {y};
+ int ex = ux.i >> 52 & 0x7ff;
+ int ey = uy.i >> 52 & 0x7ff;
+ int sx = ux.i >> 63;
+ uint64_t i;
- /* in the followings uxi should be ux.i, but then gcc wrongly adds */
- /* float load/store to inner loops ruining performance and code size */
- uint64_t uxi = ux.i;
+ /* in the followings uxi should be ux.i, but then gcc wrongly adds */
+ /* float load/store to inner loops ruining performance and code size */
+ uint64_t uxi = ux.i;
- if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff)
- return (x*y)/(x*y);
- if (uxi<<1 <= uy.i<<1) {
- if (uxi<<1 == uy.i<<1)
- return 0*x;
- return x;
- }
+ if (uy.i << 1 == 0 || isnan(y) || ex == 0x7ff)
+ return (x * y) / (x * y);
+ if (uxi << 1 <= uy.i << 1) {
+ if (uxi << 1 == uy.i << 1)
+ return 0 * x;
+ return x;
+ }
- /* normalize x and y */
- if (!ex) {
- for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1);
- uxi <<= -ex + 1;
- } else {
- uxi &= -1ULL >> 12;
- uxi |= 1ULL << 52;
- }
- if (!ey) {
- for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1);
- uy.i <<= -ey + 1;
- } else {
- uy.i &= -1ULL >> 12;
- uy.i |= 1ULL << 52;
- }
+ /* normalize x and y */
+ if (!ex) {
+ for (i = uxi << 12; i >> 63 == 0; ex--, i <<= 1)
+ ;
+ uxi <<= -ex + 1;
+ } else {
+ uxi &= -1ULL >> 12;
+ uxi |= 1ULL << 52;
+ }
+ if (!ey) {
+ for (i = uy.i << 12; i >> 63 == 0; ey--, i <<= 1)
+ ;
+ uy.i <<= -ey + 1;
+ } else {
+ uy.i &= -1ULL >> 12;
+ uy.i |= 1ULL << 52;
+ }
- /* x mod y */
- for (; ex > ey; ex--) {
- i = uxi - uy.i;
- if (i >> 63 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- uxi <<= 1;
- }
- i = uxi - uy.i;
- if (i >> 63 == 0) {
- if (i == 0)
- return 0*x;
- uxi = i;
- }
- for (; uxi>>52 == 0; uxi <<= 1, ex--);
+ /* x mod y */
+ for (; ex > ey; ex--) {
+ i = uxi - uy.i;
+ if (i >> 63 == 0) {
+ if (i == 0)
+ return 0 * x;
+ uxi = i;
+ }
+ uxi <<= 1;
+ }
+ i = uxi - uy.i;
+ if (i >> 63 == 0) {
+ if (i == 0)
+ return 0 * x;
+ uxi = i;
+ }
+ for (; uxi >> 52 == 0; uxi <<= 1, ex--)
+ ;
- /* scale result */
- if (ex > 0) {
- uxi -= 1ULL << 52;
- uxi |= (uint64_t)ex << 52;
- } else {
- uxi >>= -ex + 1;
- }
- uxi |= (uint64_t)sx << 63;
- ux.i = uxi;
- return ux.f;
+ /* scale result */
+ if (ex > 0) {
+ uxi -= 1ULL << 52;
+ uxi |= (uint64_t)ex << 52;
+ } else {
+ uxi >>= -ex + 1;
+ }
+ uxi |= (uint64_t)sx << 63;
+ ux.i = uxi;
+ return ux.f;
}

Powered by Google App Engine
This is Rietveld 408576698