C++11标准模板(STL)- 常用数学函数 - 浮点数操作函数 - 检查第一个浮点参数是否大于等于第二个(std::isgreaterequal)

常用数学函数

检查第一个浮点参数是否大于等于第二个

复制代码
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
相关推荐
Tanecious.27 分钟前
机器视觉--python基础语法
开发语言·python
叠叠乐33 分钟前
rust Send Sync 以及对象安全和对象不安全
开发语言·安全·rust
想跑步的小弱鸡33 分钟前
Leetcode hot 100(day 3)
算法·leetcode·职场和发展
Tttian6222 小时前
Python办公自动化(3)对Excel的操作
开发语言·python·excel
xyliiiiiL2 小时前
ZGC初步了解
java·jvm·算法
爱的叹息3 小时前
RedisTemplate 的 6 个可配置序列化器属性对比
算法·哈希算法
Merokes3 小时前
关于Gstreamer+MPP硬件加速推流问题:视频输入video0被占用
c++·音视频·rk3588
独好紫罗兰3 小时前
洛谷题单2-P5713 【深基3.例5】洛谷团队系统-python-流程图重构
开发语言·python·算法
每次的天空4 小时前
Android学习总结之算法篇四(字符串)
android·学习·算法
闪电麦坤954 小时前
C#:base 关键字
开发语言·c#