最近把g++升级到了13.1.0,测试了一下三向比较运算符,结果无意中发现double类型的比较居然对了
附代码与运行截图
#include <bits/stdc++.h>
using namespace std;
int main(){
double a,b;
while(cin >> a >> b){
auto tmp= a<=>b;
if(tmp==0){
cout <<"three-way comparison:\t"<< a << "==" << b << endl;
}
if(tmp>0){
cout <<"three-way comparison:\t"<< a << ">" << b << endl;
}
if(tmp<0){
cout <<"three-way comparison:\t"<< a << "<" << b << endl;
}
if(a==b){
cout <<" :\t"<< a << "==" << b << endl;
}
if(a>b){
cout <<" :\t" << a << ">" << b << endl;
}
if(a<b){
cout <<" :\t" << a << "<" << b << endl;
}
}
}
