less()函数确定第一个参数的值是否小于第二个参数的值。如果第一个参数小于第二个参数,则返回1,否则返回0。
考虑两个数字“ x”和“ y”。语法为:
bool less(float x, float y); bool less(double x, double y); bool less(long double x, long double y); bool less(Arithmetic x, Arithmetic y);
(x,y):我们要比较的值。
参数(x,y) | 返回值 |
---|---|
x |
1 |
x>y or x=nan or y=nan | 0 |
让我们看一个简单的示例,其中x和y都是相同的类型。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-less-function.html
来源:LearnFk无涯教程网
#include <iostream> #include<math.h> using namespace std; int main() { float x=1.2; float y=1.3; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isless(x,y) : "<<isless(x,y); return 0; }
输出:
Values of x and y are : 1.2,1.3 isless(x,y) : 1
在此示例中,isless()函数确定x的值小于y。因此,它返回1。
让我们看一个简单的示例,其中x和y都是不同的类型。
#include <iostream> #include<math.h> using namespace std; int main() { float x=7.2; int y=5; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isless(x,y) : "<<isless(x,y); return 0; }
输出:
Values of x and y are : 7.2,5 isless(x,y) :0
在此示例中,isless()函数确定x的值不小于y。因此,它返回0。
让我们看一个简单的例子,当x的值为nan时。
#include <iostream> #include<math.h> using namespace std; int main() { float x= 0.0/0.0; float y=5.67; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isless(x,y) : "<<isless(x,y); return 0; }
输出:
Values of x and y are : nan,5.67 isless(x,y) : 0
在此示例中,x的值为nan。因此,该函数返回0。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕