C++11标准模板(STL)- 常用数学函数 - 浮点数操作函数 - 检查第一个浮点参数是否小于或等于第二个(std::islessequal)
常用数学函数
检查第一个浮点参数是否小于或等于第二个
std::islessequal
定义于头文件 | ||
#define islessequal(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;
//确定浮点数 x 是否小于或等于浮点数 y ,而不设置浮点异常。
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::islessequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::islessequal(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::islessequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::islessequal(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::islessequal(" << fNumber1
<< "," << fNumber2 << "): "
<< std::islessequal(fNumber1, fNumber2) << std::endl;
}
return 0;
}
输出
std::islessequal(nan,nan): false
std::islessequal(nan,nan): false
std::islessequal(0.667457,0.903339): true
std::islessequal(1.01973,0.55107): false
std::islessequal(1.16723,0.403565): false
std::islessequal(1.25123,0.319571): false
std::islessequal(1.30591,0.264886): false
std::islessequal(1.34447,0.226327): false
std::islessequal(1.37316,0.197634): false
std::islessequal(1.39536,0.175431): false
std::islessequal(0.413063,1.15773): true
std::islessequal(nan,nan): false
std::islessequal(0.963731,0.266877): false
std::islessequal(0.990891,0.134665): false
std::islessequal(0.995948,0.0899287): false
std::islessequal(0.99772,0.0674865): false
std::islessequal(0.998541,0.0540039): false
std::islessequal(0.998987,0.04501): false
std::islessequal(0.999255,0.0385834): false
std::islessequal(0.99943,0.0337625): false
std::islessequal(0.99955,0.0300123): false
std::islessequal(-0.0003649,1.02701): true
std::islessequal(1,0): false
std::islessequal(0.0133882,0.99991): true
std::islessequal(-0.57634,-0.81721): false
std::islessequal(0.989857,-0.142064): false
std::islessequal(0.401336,0.915931): true
std::islessequal(-0.971594,0.236656): true
std::islessequal(0.957956,-0.286916): false
std::islessequal(0.643719,0.765262): true
std::islessequal(0.86954,-0.493862): false
std::islessequal(0.899437,-0.43705): false
std::islessequal(-0.202925,1.60388): true
原文地址:https://blog.csdn.net/qq_40788199/article/details/143636372
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!