小编imb*_*bAF的帖子

关于 C++ while 循环的语法混淆

我最近开始学习 C++,我有一个关于我们讲座中关于声明不同类型变量时的准确性的练习的语法问题,在这种情况下是float和double。

#include <iostream>
using namespace std ;

int main()
{
    // Accuracy test with float
    float eps_f = 1.0 ;
    while (float(1.0 + eps_f) != 1.0)
    eps_f /= 2.0 ;
    cout << "Resolving capacity float approximately: " << 2*eps_f << endl ;
    
     // Accuracy test with double
    double eps_d = 1.0 ;
    while (1.0 + eps_d != 1.0)
    eps_d /= 2.0 ;
    cout << "Resolving capacity double approximately : " << 2*eps_d << endl ; …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c++ ×1