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
相关推荐
kikyo哎哟喂几秒前
Java 代理模式详解
java·开发语言·代理模式
_OLi_2 分钟前
力扣 LeetCode 106. 从中序与后序遍历序列构造二叉树(Day9:二叉树)
数据结构·算法·leetcode
duration~6 分钟前
SpringAOP模拟实现
java·开发语言
一条晒干的咸魚15 分钟前
【Web前端】实现基于 Promise 的 API:alarm API
开发语言·前端·javascript·api·promise
ahadee30 分钟前
蓝桥杯每日真题 - 第18天
c语言·vscode·算法·蓝桥杯
就爱六点起32 分钟前
C/C++ 中的类型转换方式
c语言·开发语言·c++
我明天再来学Web渗透34 分钟前
【SQL50】day 2
开发语言·数据结构·leetcode·面试
猫猫的小茶馆36 分钟前
【C语言】指针常量和常量指针
linux·c语言·开发语言·嵌入式软件
地平线开发者1 小时前
CPU& 内存加压工具 stress-ng 介绍
算法·自动驾驶
XY.散人1 小时前
初识算法 · 分治(2)
算法