首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >1.#QNAN错误C++

1.#QNAN错误C++
EN

Stack Overflow用户
提问于 2011-01-07 01:31:59
回答 1查看 53.9K关注 0票数 15

我是个编程新手,正在尝试写一个新的程序。在检查我的程序时,它返回了错误代码1.#QNAN。我试着隔离变量并研究答案,但找不到任何解决方案。

我的代码:

代码语言:javascript
复制
 // This is a program to decide what culvert should be properly used for a specific installation
// using given measurements and data
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
// initializing functions 
double slope_function();
double cbasin();
// initializing classes: Subdivisions specs

//intitializing global variables
double edge_road =0;
double up_stream  =0;
double down_stream =0;
double tbm =0.0;

//double culv_length =0;
double slope = 0.0 ;
char street_name[1001];
int min_culv = 15;
double up_strm_culv =0;
double dwn_strm_culv =0;


int main (int nNumberofArgs, char* pszArgs[])
{
    cout<< "This program will allow the surveyor to double check their calculations\n";
    cout << "in deciding what size, type, and requirements are allowed for the\n";
    cout << "installation of culverts in Terrebonne Parish.\n\n";



// begin input
   cout << "what is the name of the street\nwhere the culverts will be installed: ";
   cin.getline (street_name,1000);
   cout << endl;
   cout << "What is the Benchmark: ";
   cin >> tbm;
   cout << endl;
   cout << "What is the elevation of the edge of the road: ";
   cin >> edge_road;
   cout << endl;
   cout << "What is the up-stream culvert size: ";
   cin >> up_strm_culv;
   cout << endl;
   cout << "What is the culverts up-stream inverted elevation: ";
   cin >> up_stream;
   cout << endl;
   cout << "What is the down-stream culvert size: ";
   cin >> dwn_strm_culv;
   cout << endl;
   cout << "What is the culverts down-stream inverted elevation: ";
   cin >> down_stream;
   cout << endl;
   cout << "What is the length of culvert requested: ";
   cin >> culv_length;


   cout << "Your slope is : "; 
   cout << slope_function();
   cout << endl;
   cout << street_name;
   cout << endl;
   cout << cbasin();


    cout << endl;
  // wait until user is ready before terminating program
  // to allow the user to see the program results 
  system ("pause");
  return 0;
}  

// slope function 
double slope_function()
{
    double riseoverrun = 0.0;
    slope = (up_stream - down_stream)/ culv_length;
    return slope;
}


// Catch Basin function
double cbasin ( )
{
    double cb = 0;
    cb = culv_length / 60;
    cout << endl;
    cout << "You need ";
   cout << cb;
   cout << " catch basins for this job.";
   cout << endl;
}
EN

回答 1

Stack Overflow用户

发布于 2011-01-07 01:35:37

1#QNAN是"quiet NAN“的字符串表示。"NAN“是”非数字“,仅适用于浮点数和双精度数。

NANs实际上对于表示"null“值非常有用(而不是挑选一些真正的数字,然后希望你不需要那个数字作为它的自然含义)。

如果某些数学运算“无效”(例如,取负数的对数),则可能会返回NAN。

您可以使用以下命令从C++生成QNAN

代码语言:javascript
复制
double d = std::numeric_limits<double>::quiet_NaN();

NAN上的任何比较操作(==、<=等)都返回false,即使将其等价性与其自身进行比较也是如此,除了!=,它总是返回true (即使与自身进行比较)。

(代码中的实际bug似乎是一个返回double但没有return语句的函数)。

票数 46
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4617796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档