小编hal*_*ley的帖子

循环中的 C++ 浮点错误与单个表达式中的浮点错误

(免责声明:我知道浮点数不能精确表示十分之一。)

我在 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)

c++ floating-point compiler-optimization

3
推荐指数
1
解决办法
62
查看次数

发送消息并立即删除它

我试图让Discord机器人在10秒之后删除它的"系统消息",因为我已经看到很多"无效命令"错误和"完成!" 通知,我想清除它们的实际消息.这与删除用户拥有命令的消息不同; 我已经具备了这种能力.

javascript discord discord.js

1
推荐指数
2
解决办法
2万
查看次数