Namespaces
Variants

islessgreater

From cppreference.net
< c ‎ | numeric ‎ | math
Common mathematical functions
Functions
Basic operations
(C99)
(C99)
(C99)
(C99) (C99) (C99) (C23)
Maximum/minimum operations
Exponential functions
Power functions
Trigonometric and hyperbolic functions
Nearest integer floating-point
(C99) (C99) (C99)
(C23) (C23) (C23) (C23)
Floating-point manipulation
Narrowing operations
(C23)
(C23)
(C23)
(C23)
(C23)
(C23)
Quantum and quantum exponent
Decimal re-encoding functions
Total order and payload functions
Classification
(C99)
islessgreater
(C99)
(C23)

Error and gamma functions
(C99)
(C99)
(C99)
(C99)
Types
Macro constants
Special floating-point values
Arguments and return values
Error handling
Fast operation indicators
定义于头文件 <math.h>
#define islessgreater(x, y) /* 由实现定义 */
(C99 起)

判断浮点数 x 是否小于或大于浮点数 y ,且不触发浮点异常。

目录

参数

x - 浮点数值
y - 浮点数值

返回值

x < y || x > y 则返回非零整数值, 0 否则。

注释

浮点数的内置 operator < operator > 在参数包含 NaN 时可能引发 FE_INVALID 。此函数是表达式 x < y || x > y 的“静默”版本。该宏不会对 x 和 y 进行两次求值。

示例

#include <math.h>
#include <stdio.h>
int main(void)
{
    printf("islessgreater(2.0,1.0)      = %d\n", islessgreater(2.0, 1.0));
    printf("islessgreater(1.0,2.0)      = %d\n", islessgreater(1.0, 2.0));
    printf("islessgreater(1.0,1.0)      = %d\n", islessgreater(1.0, 1.0));
    printf("islessgreater(INFINITY,1.0) = %d\n", islessgreater(INFINITY, 1.0));
    printf("islessgreater(1.0,NAN)      = %d\n", islessgreater(1.0, NAN));
    return 0;
}

可能的输出:

islessgreater(2.0,1.0)      = 1
islessgreater(1.0,2.0)      = 1
islessgreater(1.0,1.0)      = 0
islessgreater(INFINITY,1.0) = 1
islessgreater(1.0,NAN)      = 0

参考文献

  • C23 标准 (ISO/IEC 9899:2024):
  • 7.12.14.5 islessgreater 宏 (p: TBD)
  • F.10.11 比较宏 (p: TBD)
  • C17 标准 (ISO/IEC 9899:2018):
  • 7.12.14.5 islessgreater 宏 (p: TBD)
  • F.10.11 比较宏 (p: TBD)
  • C11 标准 (ISO/IEC 9899:2011):
  • 7.12.14.5 islessgreater 宏 (p: 261)
  • F.10.11 比较宏 (p: 531)
  • C99标准(ISO/IEC 9899:1999):
  • 7.12.14.5 islessgreater宏(页码:241-242)

参见

(C99)
检查第一个浮点参数是否小于第二个
(函数宏)
检查第一个浮点参数是否大于第二个
(函数宏)
C++ documentation for islessgreater