SDL 2.0
e_fmod.c File Reference
#include "math_libm.h"
#include "math_private.h"
+ Include dependency graph for e_fmod.c:

Go to the source code of this file.

Functions

double attribute_hidden __ieee754_fmod (double x, double y)
 

Variables

static const double one = 1.0
 
static const double Zero [] = {0.0, -0.0,}
 

Function Documentation

◆ __ieee754_fmod()

double attribute_hidden __ieee754_fmod ( double  x,
double  y 
)

Definition at line 23 of file e_fmod.c.

24{
25 int32_t n,hx,hy,hz,ix,iy,sx,i;
26 u_int32_t lx,ly,lz;
27
28 EXTRACT_WORDS(hx,lx,x);
29 EXTRACT_WORDS(hy,ly,y);
30 sx = hx&0x80000000; /* sign of x */
31 hx ^=sx; /* |x| */
32 hy &= 0x7fffffff; /* |y| */
33
34 /* purge off exception values */
35 if((hy|ly)==0||(hx>=0x7ff00000)|| /* y=0,or x not finite */
36 ((hy|((ly|-(int32_t)ly)>>31))>0x7ff00000)) /* or y is NaN */
37 return (x*y)/(x*y);
38 if(hx<=hy) {
39 if((hx<hy)||(lx<ly)) return x; /* |x|<|y| return x */
40 if(lx==ly)
41 return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
42 }
43
44 /* determine ix = ilogb(x) */
45 if(hx<0x00100000) { /* subnormal x */
46 if(hx==0) {
47 for (ix = -1043, i=lx; i>0; i<<=1) ix -=1;
48 } else {
49 for (ix = -1022,i=(hx<<11); i>0; i<<=1) ix -=1;
50 }
51 } else ix = (hx>>20)-1023;
52
53 /* determine iy = ilogb(y) */
54 if(hy<0x00100000) { /* subnormal y */
55 if(hy==0) {
56 for (iy = -1043, i=ly; i>0; i<<=1) iy -=1;
57 } else {
58 for (iy = -1022,i=(hy<<11); i>0; i<<=1) iy -=1;
59 }
60 } else iy = (hy>>20)-1023;
61
62 /* set up {hx,lx}, {hy,ly} and align y to x */
63 if(ix >= -1022)
64 hx = 0x00100000|(0x000fffff&hx);
65 else { /* subnormal x, shift x to normal */
66 n = -1022-ix;
67 if(n<=31) {
68 hx = (hx<<n)|(lx>>(32-n));
69 lx <<= n;
70 } else {
71 hx = lx<<(n-32);
72 lx = 0;
73 }
74 }
75 if(iy >= -1022)
76 hy = 0x00100000|(0x000fffff&hy);
77 else { /* subnormal y, shift y to normal */
78 n = -1022-iy;
79 if(n<=31) {
80 hy = (hy<<n)|(ly>>(32-n));
81 ly <<= n;
82 } else {
83 hy = ly<<(n-32);
84 ly = 0;
85 }
86 }
87
88 /* fix point fmod */
89 n = ix - iy;
90 while(n--) {
91 hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
92 if(hz<0){hx = hx+hx+(lx>>31); lx = lx+lx;}
93 else {
94 if((hz|lz)==0) /* return sign(x)*0 */
95 return Zero[(u_int32_t)sx>>31];
96 hx = hz+hz+(lz>>31); lx = lz+lz;
97 }
98 }
99 hz=hx-hy;lz=lx-ly; if(lx<ly) hz -= 1;
100 if(hz>=0) {hx=hz;lx=lz;}
101
102 /* convert back to floating value and restore the sign */
103 if((hx|lx)==0) /* return sign(x)*0 */
104 return Zero[(u_int32_t)sx>>31];
105 while(hx<0x00100000) { /* normalize x */
106 hx = hx+hx+(lx>>31); lx = lx+lx;
107 iy -= 1;
108 }
109 if(iy>= -1022) { /* normalize output */
110 hx = ((hx-0x00100000)|((iy+1023)<<20));
111 INSERT_WORDS(x,hx|sx,lx);
112 } else { /* subnormal output */
113 n = -1022 - iy;
114 if(n<=20) {
115 lx = (lx>>n)|((u_int32_t)hx<<(32-n));
116 hx >>= n;
117 } else if (n<=31) {
118 lx = (hx<<(32-n))|(lx>>n); hx = sx;
119 } else {
120 lx = hx>>(n-32); hx = sx;
121 }
122 INSERT_WORDS(x,hx|sx,lx);
123 x *= one; /* create necessary signal */
124 }
125 return x; /* exact output */
126}
signed int int32_t
GLint GLint GLint GLint GLint GLint y
Definition: SDL_opengl.h:1574
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLdouble n
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
static const double Zero[]
Definition: e_fmod.c:21
static const double one
Definition: e_fmod.c:21
unsigned int u_int32_t
Definition: math_private.h:31
#define EXTRACT_WORDS(ix0, ix1, d)
Definition: math_private.h:99
#define INSERT_WORDS(d, ix0, ix1)
Definition: math_private.h:127

References EXTRACT_WORDS, i, INSERT_WORDS, one, and Zero.

Variable Documentation

◆ one

const double one = 1.0
static

Definition at line 21 of file e_fmod.c.

Referenced by __ieee754_fmod().

◆ Zero

const double Zero[] = {0.0, -0.0,}
static

Definition at line 21 of file e_fmod.c.

Referenced by __ieee754_fmod().