我的程序的最终结果在声明为e1和energy的两个双变量中产生以下值:
e1 = 278872475.434922
energy = 2982053.000000
Run Code Online (Sandbox Code Playgroud)
我的最终结果是per = e1除以能量.实际答案是93.5169.但是,这通过以下方式在C中完成:per = e1/energy给出了完全不同的答案?问题是什么?
我想将float的内容复制到C++中的字符串.这不起作用.
#include <iostream>
#include <sstream>
using namespace std;
int main() {
float ans = getFloat();
stringstream ss;
string strAns;
ss >> ans;
strAns = ss.str();
cout << strAns << "\n"; // displays "0"
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做呢?
我正在寻找C#中floor(x)的实现,以便它与C++版本匹配.
floor of 2.3 is 2.0
floor of 3.8 is 3.0
floor of -2.3 is -3.0
floor of -3.8 is -4.0
Run Code Online (Sandbox Code Playgroud)
由于C++审阅者将检查我的代码,floor在C#中哪些实现是合理的,这样他就不会拉出他的(最后剩下的)头发?
编辑:这里有很多不满的成员,因为这个问题在网站上有重复.在我的辩护中,我尝试首先搜索答案,也许我使用的搜索关键字很差,但我找不到这个特定代码示例的直接,明确的答案.我很少知道**2009**中有一个会从那里链接到那里.
这是一个编码示例:
#include <iostream>
using namespace std;
int main() {
float x = 0.1 * 7;
if (x == 0.7)
cout << "TRUE. \n";
else
cout << "FALSE. \n";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这导致FALSE.但是,当我输出x时,确实输出为0.7.说明?
这是我试过的:
public class LongToDoubleTest{
public static void main(String... args) {
System.out.println(Long.MAX_VALUE);
System.out.println(Long.MAX_VALUE/2);
System.out.println(Math.floor(Long.MAX_VALUE/2));
System.out.println(new Double(Math.floor(Long.MAX_VALUE/2)).longValue());
}
}
Run Code Online (Sandbox Code Playgroud)
这是输出:
9223372036854775807
4611686018427387903
4.6116860184273879E18
4611686018427387904
Run Code Online (Sandbox Code Playgroud)
我最初想弄清楚,是否有可能将Long.MAX_VALUE的一半保持在双倍而不会丢失数据,所以我对所有这些行进行了测试,除了最后一行.所以看来我是对的,最后一次3失踪了.然后,为了澄清它,我添加了最后一行.并没有3出现但是4.所以我的问题是,从那些4出现的地方以及它为什么4而不是3.因为4这里实际上是一个不正确的值.PS我的知识很差IEEE 754,所以我发现的行为绝对是正确的,但这4显然是错误的价值.
我有这个变量
unsigned long long latitude = 29.47667;
Run Code Online (Sandbox Code Playgroud)
当我将此值转换为这样的数组时
ar[7] = (uint8_t)((latitude >> 56) & 0xFF);
ar[6] = (uint8_t)((latitude >> 48) & 0xFF);
ar[5] = (uint8_t)((latitude >> 40) & 0xFF);
ar[4] = (uint8_t)((latitude >> 32) & 0xFF);
ar[3] = (uint8_t)((latitude >> 24) & 0xFF);
ar[2] = (uint8_t)((latitude >> 16) & 0xFF);
ar[1] = (uint8_t)((latitude >> 8) & 0xFF);
ar[0] = (uint8_t)(latitude & 0xFF);
Run Code Online (Sandbox Code Playgroud)
然后使用tcp socket将其发送到服务器.当我发送时,我以十六进制打印值,然后我0x1d全部休息.
如何在将unsigned long long转换为int时将确切的值发送到服务器.
每种编程语言都有自己的方法将整数转换为浮点数,将 01010 转换为其他 01010。如果您看到 ASM 生成的代码,它使用协处理器指令向用户隐藏真实值。
但实际情况如何呢?如何通过算法计算尾数、指数?
我在 Python 的字典列表中有这组值。
[
{'dep_price': '42.350', 'dep_date': '8-Mar-2017', 'trip_type': 'dep'},
{'dep_price': '42.350', 'dep_date': '9-Mar-2017', 'trip_type': 'dep'},
{'dep_price': '36.350', 'dep_date': '10-Mar-2017', 'trip_type': 'dep'}
]
Run Code Online (Sandbox Code Playgroud)
如何根据字段“dep_price”作为浮点值对它们进行排序?
Double.toString(0.1)产生“0.1”,但 0.1 是浮点数。
浮点数无法在程序语言中精确表示,但 Double.toString 会产生精确的结果(0.1),它是如何做到的,它总是产生数学上等于双精度文字的结果吗?
假设文字是双精度的。
这是我看到的问题:
当使用Apache POI读取excel文件时,XSSFCell.getNumericCellValue只能返回double,如果我使用BigDecimal.valueOf将其转换为BigDecimal,总是安全的,为什么?
我有一个带有浮点数的一维数组。如何找出偶数元素的数量?
因为它包含浮动元素,所以我不能使用 condition if (v[i] % 2 == 0)。