islessequal()函数检查第一个参数的值是否小于或等于第二个参数。如果第一个参数的值小于或等于第二个参数的值,则返回1,否则返回0。
bool islessequal(float x,float y); bool islessequal(double x,double y); bool islessequal(long double x,long double y); bool islessequal(Arithmetic x,Arithmetic y);
(x,y):我们要比较的值。
参数(x,y) | 返回值 |
---|---|
x | 1 |
x>y or x=nan or y=nan | 0 |
让我们看一个简单的示例,其中x和y都是相同的类型。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 3.4; float y=3.4; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessequal(x,y) : "<<islessequal(x,y); return 0; }
输出:
Values of x and y are : 3.4,3.4 islessequal(x,y) : 1
在此示例中,islessequal()函数确定x和y相等。因此,它返回1。
让我们看一个简单的示例,其中x和y都是不同的类型。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 7.8; int y=2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessequal(x,y) : "<<islessequal(x,y); return 0; }
输出:
Values of x and y are : 7.8,2 islessequal(x,y) : 0
在此示例中,x大于y。因此,该函数返回0。
让我们看一个简单的例子。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 0.0/0.0; float y=0.0/0.0; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"islessequal(x,y) : "<<islessequal(x,y); return 0; }
输出:
Values of x and y are : nan,nan islessequal(x,y) : 0
在此示例中,x和y均为NAN。因此,该函数返回0。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Tony Bai · Go语言第一课 -〔Tony Bai〕