常用数学函数
检查第一个浮点参数是否大于等于第二个
std::isgreaterequal
|-------------------------------------------------------------|---|---------|
| 定义于头文件 <math.h>
| | |
| #define isgreaterequal(x, y) /* implementation defined */ | | (C99 起) |
确定浮点数 x
是否大于或等于浮点数 y
,而不设置浮点异常。
参数
|---|---|-----|
| x | - | 浮点值 |
| y | - | 浮点值 |
返回值
若 x >= y 则为非零整数值,否则为 0 。
注意
若一或两个参数为 NaN ,则内建的 operator>= 对浮点数可能引发 FE_INVALID 。此宏是 operator>= 的"安静"版本。
调用示例
#include <iostream>
#include <cstdlib>
#include <typeinfo>
#include <cinttypes>
#include <cmath>
#include <math.h>
#include <tgmath.h>
int main()
{
std::cout << std::boolalpha;
//检查第一个浮点参数是否大于等于第二个
for (int i = 0; i <= 10; i += 1)
{
const float fNumber = std::acos(-1) / 2 / i;
const float fNumber1 = std::acos(fNumber) - i / 10;
const float fNumber2 = std::asin(fNumber) + i / 10;
std::cout << "std::isgreaterequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::isgreaterequal(fNumber1, fNumber2) << std::endl;
}
std::cout << std::endl;
for (int i = 0; i <= 10; i += 1)
{
const float fNumber = std::cos(-1) / 2 / i;
const float fNumber1 = std::cos(fNumber) - i / 10;
const float fNumber2 = std::sin(fNumber) + i / 10;
std::cout << "std::isgreaterequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::isgreaterequal(fNumber1, fNumber2) << std::endl;
}
std::cout << std::endl;
for (int i = 0; i <= 10; i += 1)
{
const float fNumber = std::tan(i);
const float fNumber1 = std::cos(fNumber) - i / 10;
const float fNumber2 = std::sin(fNumber) + i / 10;
std::cout << "std::isgreaterequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::isgreaterequal(fNumber1, fNumber2) << std::endl;
}
return 0;
}
输出
std::isgreaterequal(nan,nan): false
std::isgreaterequal(nan,nan): false
std::isgreaterequal(0.667457,0.903339): false
std::isgreaterequal(1.01973,0.55107): true
std::isgreaterequal(1.16723,0.403565): true
std::isgreaterequal(1.25123,0.319571): true
std::isgreaterequal(1.30591,0.264886): true
std::isgreaterequal(1.34447,0.226327): true
std::isgreaterequal(1.37316,0.197634): true
std::isgreaterequal(1.39536,0.175431): true
std::isgreaterequal(0.413063,1.15773): false
std::isgreaterequal(nan,nan): false
std::isgreaterequal(0.963731,0.266877): true
std::isgreaterequal(0.990891,0.134665): true
std::isgreaterequal(0.995948,0.0899287): true
std::isgreaterequal(0.99772,0.0674865): true
std::isgreaterequal(0.998541,0.0540039): true
std::isgreaterequal(0.998987,0.04501): true
std::isgreaterequal(0.999255,0.0385834): true
std::isgreaterequal(0.99943,0.0337625): true
std::isgreaterequal(0.99955,0.0300123): true
std::isgreaterequal(-0.0003649,1.02701): false
std::isgreaterequal(1,0): true
std::isgreaterequal(0.0133882,0.99991): false
std::isgreaterequal(-0.57634,-0.81721): true
std::isgreaterequal(0.989857,-0.142064): true
std::isgreaterequal(0.401336,0.915931): false
std::isgreaterequal(-0.971594,0.236656): false
std::isgreaterequal(0.957956,-0.286916): true
std::isgreaterequal(0.643719,0.765262): false
std::isgreaterequal(0.86954,-0.493862): true
std::isgreaterequal(0.899437,-0.43705): true
std::isgreaterequal(-0.202925,1.60388): false