Rounding Errors: the Achilles Heel of math programming

虽然用程序写数学题很开心,但也有些问题,比如说rounding error。

#include<bits/stdc++.h>
using namespace std;
int main(){
	double a=1.0/99999999.0;
	double b=99999998.0/99999999.0;
	cout<<a<<endl;
	cout<<b<<endl;
	cout<<a+b;
	return 0;
}
/*
output:
1e-008
1
1
*/

所以,有时间的话,还是写个struct来存这些分数还有surd等。

posted @ 2023-02-13 15:39  Corylus  阅读(18)  评论(0编辑  收藏  举报