函数std::frexp与其对偶std::ldexp能一起用于操纵浮点数的表示,而无需直接的位操作。 示例 比较不同的浮点分解函数 运行此代码 #include <iostream>#include <cmath>#include <limits>intmain(){doublef=123.45;std::cout<<"Given the number "<<f<<" or "<<std::hexfloat<<f<<std::defaultfloat<<"...
二进制系统(其中 FLT_RADIX 为2 )上, frexp 可实现为 { *exp = (value == 0) ? 0 : (int)(1 + std::logb(value)); return std::scalbn(value, -(*exp)); }函数std::frexp 与其对偶 std::ldexp 能一起用于操纵浮点数的表示,而无需直接的位操作。
double frexp ( Integer num, int* exp ); (A) (C++23 起为 constexpr) 1-3) 分解给定的浮点数 x 为正规化小数和二的整数指数。标准库提供所有以无 cv 限定的浮点数类型作为参数 num 的类型的 std::frexp 重载。(C++23 起)A) 为所有整数类型提供额外重载,将它们当做 double。 (C++11 起)参数...
std::frexp,std::frexpf,std::frexpl Defined in header<cmath> (1) floatfrexp(floatnum,int*exp); doublefrexp(doublenum,int*exp); longdoublefrexp(longdoublenum,int*exp); (until C++23) constexpr/* floating-point-type */ frexp(/* floating-point-type */num,int*exp); ...