找到以 10 为底的双倍的指数和尾数
Find exponent and mantissa of a double to the base 10
本文关键字:指数 更新时间:2023-10-16
我需要将双倍类型的数值分解为:指数和尾数。我发现我可以使用 math.h
中的 frexp()
函数来做到这一点。但是,此函数假定基数为 2。
有没有办法让我找到以 10 为底的指数和尾数——这样返回的尾数和指数都是整数类型。
#include <cstdio>
#include <cmath>
int main()
{
int e;
const double x = 1024;
const double fraction = frexp(x, &e);
std::printf("x = %.2lf = %.2lf * 2^%dn", x, fraction, e);
}
我拥有的编译器是:gcc(Ubuntu/Linaro 4.6.4-6ubuntu2)4.6.4
基本对数会有所帮助。这个想法是使用std::log10
来获取指数,然后将原始数字除以 10^exp 得到尾数。
double frexp10(double arg, int * exp)
{
*exp = (arg == 0) ? 0 : 1 + (int)std::floor(std::log10(std::fabs(arg) ) );
return arg * std::pow(10 , -(*exp));
}
相关文章:
- 使用简单类型列表实现的指数编译时间.为什么
- 如何从组合指数中找到仓位
- 正在读取 obj 文件!(指数)
- C++:快速模块化指数
- 在C++不使用 POW 的情况下处理负指数
- 比较向量中的元素时所花费的时间呈指数级增长
- 如何将包含指数的 QString 转换为C++中的双倍?
- 将数字提高到一个巨大的指数
- 负指数是否必然意味着未定义的行为
- 整数的指数速记
- 在矩阵逆变器上工作,由于某种原因,我的指数循环不起作用
- 自定义提升多精度指数中的位数
- 如何计算复矩阵的指数
- 用C++打印指数形式的素数分解
- 为什么Regex(c++)需要指数时间
- 指数近似不适合小输入或大输入
- 如果 std::numeric_limits<float>::is_iec559 为真,这是否意味着我可以以明确定义的方式提取指数和尾数?
- 在 c++ 中创建具有指数分布的随机数(可视化标准)
- 使用双精度运算的快速 SSE 低精度指数
- C ++指数计算器错误