| C++ Builder 串口控件 | | C++ Builder 编程技巧 | | C++ Builder 操作指南 | | C++ Builder 参考手册 | | 基础知识 | | cfloat 浮点数 | | cmath 数学函数 | | • acos, acosf, acosl | | • acosh, acoshf, acoshl | | • asin, asinf, asinl | | • asinh, asinhf, asinhl | | • atan, atanf, atanl | | • atan2, atan2f, atan2l | | • atanh, atanhf, atanhl | | • ceil, ceilf, ceill | | • copysign, copysignf, copysignl | | • cos, cosf, cosl | | • cosh, coshf, coshl | | • exp, expf, expl | | • exp2, exp2f, exp2l | | • expm1, expm1f, expm1l | | • fabs, fabsf, fabsl | | • floor, floorf, floorl | | • fmod, fmodf, fmodl | | • frexp, frexpf, frexpl | | • hypot, hypotf, hypotl | | • ldexp, ldexpf, ldexpl | | • log, logf, logl | | • log10, log10f, log10l | | • log1p, log1pf, log1pl | | • log2, log2f, log2l | | • modf, modff, modfl | | • nan, nanf, nanl | | • poly, polyl | | • pow, powf, powl | | • pow10, pow10l | | • round, roundf, roundl | | • sin, sinf, sinl | | • sinh, sinhf, sinhl | | • sqrt, sqrtf, sqrtl | | • tan, tanf, tanl | | • tanh, tanhf, tanhl | | • trunc, truncf, truncl | | • _exception, _exceptionl | | • _matherr, _matherrl | | • HUGE_VAL, HUGE_VALF, HUGE_VALL, _LHUGE_VAL | | • EDOM, ERANGE | | • _mexcep, DOMAIN, SING, OVERFLOW, UNDERFLOW, TLOSS, PLOSS, STACKFAULT | | • M_E, M_LOG2E, M_LOG10E, M_LN2, M_LN10 | | • M_PI, M_PI_2, M_PI_4, M_1_PI, M_2_PI, M_1_SQRTPI, M_2_SQRTPI | | • M_SQRT2, M_SQRT_2 | | • DOMAIN error 定义域错误 | | cstdlib 标准库函数 | | System 字符串 | | System 日期和时间 | | System.Math.hpp 数学函数 | | 其他数据类型 | | VCL 基础类 | | VCL 应用程序 | | Pictures 图片 | | Graphics 绘图 | | Additional 控件 | | System 控件 | | A ~ Z 字母顺序排列的目录 | | 网友留言/技术支持 |
|
| frexp, frexpf, frexpl - 把 x 用二进位科学计数法表示,求有效数字和指数 |
函数原型:
| 函数原型 |
C90 |
C99 |
C++98 |
C++11 |
| double frexp(double x, int *y); |
√ |
√ |
√ |
√ |
| float frexpf(float x, int *y); |
|
√ |
|
|
| long double frexpl(long double x, int *y); |
|
√ |
|
|
| float frexp(float x, int *y); |
|
|
√ |
√ |
| long double frexp(long double x, int *y); |
|
|
√ |
√ |
头文件:
#include <cmath>
命名空间:
std
参数:
x:需要用二进位科学计数法表示的浮点数,定义域范围为 [-Infinity, +Infinity]
y:用来接收指数的返回值
返回值:
返回值:有效数字,值域范围:(-1.0, -0.5] ∪ [0.5, 1.0)
y:指数,x = 有效数字 × 2y,值域范围:根据不同精度的浮点数
如果 w = frexp(x, &y);,那么
x = w × 2y,即 x = w * exp2(y); 也就是 x = ldexp(w, y);
例:12.34 = 0.77125 × 24
-8.2 × 10-20 = -0.756316507022092 × 2-63
例子:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double Xes[] = { 12.34, -987.65, 5.43e50, -8.2e-20, (double)Infinity, (double)-Infinity };
UnicodeString s;
for(size_t i=0; i<sizeof(Xes)/sizeof(Xes[0]); i++)
{
double x = Xes[i];
int y;
double w = std::frexp(x, &y);
Memo1->Lines->Add(s.sprintf(L"%g = %g * exp2(%d)", x, w, y));
Memo1->Lines->Add(s.sprintf(L"%g * exp2(%d) = %g", w, y, w*std::exp2(y)));
Memo1->Lines->Add(s.sprintf(L"ldexp(%g, %d) = %g", w, y, std::ldexp(w,y)));
Memo1->Lines->Add(L"");
}
} |
12.34 = 0.77125 * exp2(4) 即 12.34 = 0.77125 × 24
-8.2E-20 = -0.756316507022092 * exp2(-63) 即 -8.2 × 10-20 = -0.756316507022092 × 2-63

兼容性:
| 函数 \ C++ Builder 编译器 |
bcc32 |
clang32 |
clang64 |
| frexp |
√ |
√ |
√ |
| frexpf |
|
版本 ≥ 10.2 Tokyo Update 1 |
√ |
| frexpl |
√ |
√ |
√ |
相关链接:
• exp2 • ldexp • _matherr • 浮点数异常处理
|
|
|
|