c++ - 从科学计数法中获取指数

标签 c++

我们如何从“科学”符号中提取指数和符号?

如果我们用 printf("%lf %e") 打印一个 double 值,它显示 par ex.:

   normal   scientific
   ------   ----------
   -888.3   -8.88e2    
    1.23     1.23e0    
    3.001    3.1e-1

How to get Exponent of Scientific Notation in Matlab中指出的解决方案

x = floor(log10(N))

仅适用于正值 N。对于 -N,它显示 -nan(ind)。显然 Log10() 具有负值是不允许的。

最佳答案

你不关心数字的符号,你只需要指数,所以你可以安全地去掉符号:

log10(abs(N))

其中 abs 返回 N 的绝对值,它总是非负的,因此可以用作 log10 的参数。

关于c++ - 从科学计数法中获取指数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41639010/

相关文章:

c++ - 错误 : invalid use of non-static data member

c++ - 使用c++访问Internet Explorer

c++ - 模板类类型调整

c++ - 创建未初始化的 SSE 值

c++ - 在调整 QWidget 大小时调整 QWidget 中的 QTextEdit 大小

C++ : What is the usage of int ('0' ) in this code?

c++ - 无法从文件中读取

c++ - 编译器会在析构函数中优化 memset 吗?

c++ - 排序 vector 不断修改数据并打印不正确的结果

c++ - C++0x 中有哪些新的 Unicode 函数?