首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::fdim

Defined in header <cmath>

?

?

float fdim( float x, float y );

(1)

(since C++11)

double fdim( double x, double y );

(2)

(since C++11)

long double fdim( long double x, long double y );

(3)

(since C++11)

Promoted fdim( Arithmetic1 x, Arithmetic2 y );

(4)

(since C++11)

1-3%29返回之间的正差xy,也就是说,如果x>y、回报x-y,否则为%28x≤y%29,返回+0。

的所有参数组合的一组重载或函数模板算术类型不包括在1-3%29。如果有任何争论积分型,它被铸造成double.如果有任何争论long double,则返回类型Promoted也是long double,否则返回类型总是double...

参数

x, y

-

values of floating-point or integral types

返回值

如果成功,则返回x和y之间的正差。

如果溢出导致范围错误,+HUGE_VAL,,,+HUGE_VALF,或+HUGE_VALL会被归还。

如果由于下流发生范围错误,则返回舍入%29后的正确值%28。

错误处理

错误按数学[医]错误处理...

如果实现支持ieee浮点算法%28IEC 60559%29,

  • 如果任一参数都是nan,则返回nan。

注记

相当于std::fmax(x-y, 0),除NAN处理要求外。

二次

代码语言:javascript
复制
#include <iostream>
#include <cmath>
#include <cerrno>
#include <cstring>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
    std::cout << "fdim(4, 1) = " << std::fdim(4, 1)
              << " fdim(1, 4) = " << std::fdim(1, 4) << '\n'
              << "fdim(4,-1) = " << std::fdim(4, -1)
              << " fdim(1,-4) = " << std::fdim(1, -4) << '\n';
    // error handling 
    errno=0; std::feclearexcept(FE_ALL_EXCEPT);
    std::cout << "fdim(1e308, -1e308) = " << std::fdim(1e308, -1e308) << '\n';
    if(errno == ERANGE)
        std::cout << "    errno == ERANGE: " << std::strerror(errno) << '\n';
    if(std::fetestexcept(FE_OVERFLOW))
        std::cout << "    FE_OVERFLOW raised\n";
}

二次

产出:

二次

代码语言:javascript
复制
fdim(4, 1) = 3 fdim(1, 4) = 0
fdim(4,-1) = 5 fdim(1,-4) = 5
fdim(1e308, -1e308) = inf
    errno == ERANGE: Numerical result out of range
    FE_OVERFLOW raised

二次

另见

abs(int)labsllabs (C++11)

computes absolute value of an integral value (|x|) (function)

fmax (C++11)

larger of two floating point values (function)

c FDIM文件

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com