std::remainder
Defined in header <cmath> | | |
|---|---|---|
float remainder( float x, float y ); | (1) | (since C++11) |
double remainder( double x, double y ); | (2) | (since C++11) |
long double remainder( long double x, long double y ); | (3) | (since C++11) |
Promoted remainder( Arithmetic1 x, Arithmetic2 y ); | (4) | (since C++11) |
1-3%29计算浮点除法操作的ieee剩余部分。x/y...
的所有参数组合的一组重载或函数模板算术类型不包括在1-3的范围内。如果有任何争论积分型,它被铸造成double.如果任何其他论点是long double,则返回类型为long double,否则就是double...
除法操作的ieee浮点余数。x/y此函数计算的值正好是x - n*y,其中的值n是积分值最近的确切值吗?x/y.当n-x/y=5时,n都被选中了。
与...形成对比std::fmod(),则返回的值不一定具有与x...
如果返回的值是0,它将具有与x...
参数
x, y | - | values of floating-point or integral types |
|---|
返回值
如果成功,则返回除法的ieee浮点余数。x/y如上文所述。
如果发生域错误,则返回支持%29的实现定义值%28 NaN。
如果由于下垫流而发生范围错误,则返回正确的结果。
如果y为零,但域错误不发生,则返回零。
错误处理
错误按数学[医]错误处理...
域错误可能发生在y是零。
如果实现支持ieee浮点算法%28IEC 60559%29,
- 电流舍入方式没有效果。
FE_INEXACT永远不会被提出,结果总是准确的。
- 如果
x是±∞和y不是南,南回来了FE_INVALID提出来
- 如果
y是±0和x不是南,南回来了FE_INVALID提出来
- 如果任一参数都是nan,则返回nan。
注记
POSIX要求,则域错误将发生在以下情况下:x是无限的或y是零。
std::fmod,但不是std::remainder对于将浮点类型无声包装为无符号整数类型非常有用:(0.0<=(y =std::fmod(std::rint(x), 65536.0))? y :65536.0+ y)在范围内[-0.0 .. 65535.0],对应于unsigned short,但是std::remainder(std::rint(x), 65536.0)在范围内[-32767.0, +32768.0],它超出了signed short...
例
二次
#include <iostream>
#include <cmath>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
int main()
{
std::cout << "remainder(+5.1, +3.0) = " << std::remainder(5.1,3) << '\n'
<< "remainder(-5.1, +3.0) = " << std::remainder(-5.1,3) << '\n'
<< "remainder(+5.1, -3.0) = " << std::remainder(5.1,-3) << '\n'
<< "remainder(-5.1, -3.0) = " << std::remainder(-5.1,-3) << '\n';
// special values
std::cout << "remainder(-0.0, 1.0) = " << std::remainder(-0.0, 1) << '\n'
<< "remainder(5.1, Inf) = " << std::remainder(5.1, INFINITY) << '\n';
// error handling
std::feclearexcept(FE_ALL_EXCEPT);
std::cout << "remainder(+5.1, 0) = " << std::remainder(5.1, 0) << '\n';
if(fetestexcept(FE_INVALID))
std::cout << " FE_INVALID raised\n";
}二次
可能的产出:
二次
remainder(+5.1, +3.0) = -0.9
remainder(-5.1, +3.0) = 0.9
remainder(+5.1, -3.0) = -0.9
remainder(-5.1, -3.0) = 0.9
remainder(-0.0, 1.0) = -0
remainder(5.1, Inf) = 5.1
remainder(+5.1, 0) = -nan
FE_INVALID raised二次
另见
div(int)ldivlldiv (C++11) | computes quotient and remainder of integer division (function) |
|---|---|
fmod | remainder of the floating point division operation (function) |
remquo (C++11) | signed remainder as well as the three last bits of the division operation (function) |
c剩余文件
© cppreference.com在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

