float fmodf(float_x, float_y) function, math.h, c++
float fmodf(float_x, float_y) function, math.h, c++
你好,我希望有人能帮我解决这个问题。
我正在使用math.h的float fmodf(float_x,float_y)函数。
我能够正确地使用它编码,但我只是想知道有没有人知道确切的代码的功能,所以我可以更好地理解它
确切的代码取决于您的数学库(可能包含在与 C 库相同的包中)。如果你想看到一个实现,你可以看看glibc实现。这是在glibc中使用的函数(来自sysdeps/ieee754/flt-32/e_fmodf.c)。
float
__ieee754_fmodf (float x, float y)
{
int32_t n,hx,hy,hz,ix,iy,sx,i;
GET_FLOAT_WORD(hx,x);
GET_FLOAT_WORD(hy,y);
sx = hx&0x80000000; /* sign of x */
hx ^=sx; /* |x| */
hy &= 0x7fffffff; /* |y| */
/* purge off exception values */
if(hy==0||(hx>=0x7f800000)|| /* y=0,or x not finite */
(hy>0x7f800000)) /* or y is NaN */
return (x*y)/(x*y);
if(hx<hy) return x; /* |x|<|y| return x */
if(hx==hy)
return Zero[(u_int32_t)sx>>31]; /* |x|=|y| return x*0*/
/* determine ix = ilogb(x) */
if(hx<0x00800000) { /* subnormal x */
for (ix = -126,i=(hx<<8); i>0; i<<=1) ix -=1;
} else ix = (hx>>23)-127;
/* determine iy = ilogb(y) */
if(hy<0x00800000) { /* subnormal y */
for (iy = -126,i=(hy<<8); i>=0; i<<=1) iy -=1;
} else iy = (hy>>23)-127;
/* set up {hx,lx}, {hy,ly} and align y to x */
if(ix >= -126)
hx = 0x00800000|(0x007fffff&hx);
else { /* subnormal x, shift x to normal */
n = -126-ix;
hx = hx<<n;
}
if(iy >= -126)
hy = 0x00800000|(0x007fffff&hy);
else { /* subnormal y, shift y to normal */
n = -126-iy;
hy = hy<<n;
}
/* fix point fmod */
n = ix - iy;
while(n--) {
hz=hx-hy;
if(hz<0){hx = hx+hx;}
else {
if(hz==0) /* return sign(x)*0 */
return Zero[(u_int32_t)sx>>31];
hx = hz+hz;
}
}
hz=hx-hy;
if(hz>=0) {hx=hz;}
/* convert back to floating value and restore the sign */
if(hx==0) /* return sign(x)*0 */
return Zero[(u_int32_t)sx>>31];
while(hx<0x00800000) { /* normalize x */
hx = hx+hx;
iy -= 1;
}
if(iy>= -126) { /* normalize output */
hx = ((hx-0x00800000)|((iy+127)<<23));
SET_FLOAT_WORD(x,hx|sx);
} else { /* subnormal output */
n = -126 - iy;
hx >>= n;
SET_FLOAT_WORD(x,hx|sx);
x *= one; /* create necessary signal */
}
return x; /* exact output */
}
相关文章:
- System.InvalidCastException - SQL to C++ - safe_cast<float>
- 没有从阵列<float>到阵列<int>的可行转换
- cmath 是否借用了 math.h 的实现
- 数组下标的类型"float*[float]"无效
- 没有合适的构造函数可以从"float"转换为"_D3DCOLORVALUE"
- 为什么我会收到此错误?无法将 {lb, ub} 从<大括号括起来的初始值设定项列表>转换为 float(**)(float*, int)
- 将 **float array 从 C++ Dll 传递给 python
- 错误:二进制'operator*' 'float'和'float[0]'类型的操作数无效
- float* 已在 Gameobject.obj 中定义
- 如何将 qml 的文本转换为 float 和 int
- 为什么将 1 添加到 numeric_limits<float>::min() 返回 1?
- 有没有比static_cast更优雅的从int到float的演员阵容<float>?
- 编译器给出错误:format 指定类型 'float *',但参数的类型'double' [-Wformat]
- OPENCL 警告:不兼容的指针类型将'float __global[16]'传递给类型为 '__global float4 的参数 *
- 错误:无法将"float*"转换为"float"
- 如何在函数中将字符串和分数存储为(Int 或 float)
- 缩小从double到float的转换
- 着色器将uint8投射到float,并将其重新解释回uint
- C++ 错误:不存在从 "math::Vec3<float>" 到 "float" 的合适转换函数
- float fmodf(float_x, float_y) function, math.h, c++