Islessgreater
定义于头文件 <cmath>
中。
描述
确定浮点数 x
是小于还是大于浮点数 y
,而不设置浮点异常。
该库为所有 cv 非限定浮点类型提供了重载,作为参数 x
和 y
的类型 (从 C++23 开始)。
为所有其他算术类型组合提供了附加重载。
声明
- C++23
- C++11
// 1)
constexpr bool islessgreater( /* floating-point-type */ x,
/* floating-point-type */ y );
// 2)
template< class Arithmetic1, class Arithmetic2 >
constexpr bool islessgreater( Arithmetic1 x, Arithmetic2 y );
// 1)
bool islessgreater( float x, float y );
// 2)
bool islessgreater( double x, double y );
// 3)
bool islessgreater( long double x, long double y );
// 4)
template< class Arithmetic1, class Arithmetic2 >
bool islessgreater( Arithmetic1 x, Arithmetic2 y );
参数
x
, y
- 浮点或整数值
返回值
如果 x < y || x > y
为 true
,否则为 false
。
备注
浮点数的内置运算符 >
和运算符 <
可能会在其中一个或两个参数为 NaN
时引发 FE_INVALID
。此函数是表达式 x < y || x > y
的“安静”版本。
不需要严格按照 附加重载 提供附加重载。它们只需要足以确保对于它们的第一个参数 num1
和第二个参数 num2
如果 num1
或 num2
的类型是 long double,则
std::islessgreater(num1, num2)
的效果与
std::islessgreater(static_cast<long double>(num1), static_cast<long double>(num2))
相同。
否则,如果 num1
和/或 num2
的类型是 double 或整数类型,则
std::islessgreater(num1, num2)
的效果与
std::islessgreater(static_cast<double>(num1), static_cast<double>(num2))
。
否则,如果 num1
或 num2
的类型为 float,则
std::islessgreater(num1, num2)
的效果与
std::islessgreater(static_cast<float>(num1), static_cast<float>(num2))
相同。(直到 C++23)
如果 num1
和 num2
具有算术类型,则
std::islessgreater(num1, num2)
的效果与
std::islessgreater(static_cast</* common-floating-point-type */>(num1), static_cast</* common-floating-point-type */>(num2))
,
其中 /* common-floating-point-type */ 是 num1
和 num2
类型之间具有最大浮点转换等级和最大浮点转换子等级的浮点类型,整数类型的参数被认为具有与 double 相同的浮点转换等级。