小编Joc*_*Hua的帖子

“-nan”是什么意思,是什么原因造成的?

我知道 nan 的意思是“不是数字”,但是这段代码使用高斯消元算法输出“-nan”:

#include <bits/stdc++.h> 
#include <algorithm>

using namespace std;
typedef long long ll;
const int N=55;
const double eps=1e-7;
int n;

struct mat {
    int l,c;
    double p[N][N];
    double* operator [] (int i) {return p[i];}
}a;

bool flo0(double &x) {return (fabs(x)<=eps)?1:0;}

void REF() {
    for(int i=1;i<=n;i++) {
        int flag=i;
        for(int j=i;j<=n;j++) {
            if(fabs(a[j][i])>fabs(a[flag][i])) flag=j;
        }
        for(int j=1;j<=n+1;j++) swap(a[flag][j],a[i][j]);
        if(flo0(a[i][i])) continue;
        for(int j=i+1;j<=n;j++) {
            double t=a[j][i]/a[i][i];
            for(int k=i;k<=n+1;k++) {
                a[j][k]-=t*a[i][k];
            }
        }
    }
}

void RREF() {
    for(int i=n;i>=1;i--) { …
Run Code Online (Sandbox Code Playgroud)

c++ algorithm math floating-point double

5
推荐指数
1
解决办法
115
查看次数

标签 统计

algorithm ×1

c++ ×1

double ×1

floating-point ×1

math ×1