(免责声明:我知道浮点数不能精确表示十分之一。)
我在 C++ 中使用单精度浮点数(以测试舍入错误),我遇到了这种奇怪的行为。
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
// set number of sigdigs in output
cout << setprecision(9);
float singleA = 0.1 * 7.;
float singleB = 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1;
float singleC = 0.0;
for (int i = 0; i < 7; i++){
singleC += 0.1;
}
// ^ i expected that to be the same as
// 0.1 + 0.1 + 0.1 + 0.1 …
Run Code Online (Sandbox Code Playgroud) 我试图让Discord机器人在10秒之后删除它的"系统消息",因为我已经看到很多"无效命令"错误和"完成!" 通知,我想清除它们的实际消息.这与删除用户拥有命令的消息不同; 我已经具备了这种能力.