- cmath[meta header]
- std[meta namespace]
- function[meta id-type]
- cpp11[meta cpp]
namespace std {
double remquo(double x, double y, int* quo);
float remquo(float x, float y, int* quo);
long double remquo(long double x, long double y, int* quo);
Integral remquo(Integral x, Integral y, int* quo);
float remquof(float x, float y, int* quo); // C++17 から
long double remquol(long double x, long double y, int* quo); // C++17 から
}- Integral[italic]
浮動小数点数の剰余と商を求める。remquoは、「remainder (剰余)」と「quotient (商)」と意味する。
この関数は、浮動小数点数に対して除算を行い、除算の結果(商)と、その余り(剰余)を同時に求める。戻り値として剰余が返され、ポインタ引数quoに商の値が書き込まれる。
remainder()関数と同じ方法で剰余を求めて、戻り値として返す。quoが指す値は、x/yで得られた商と同じ大きさを持ち、x/yで得られた符号と同じ符号を持つ
yがゼロである場合、quoが指す値は未規定となる。またその際、定義域エラーを発生させるかゼロを返すかは、実装定義となる。定義域エラーが発生した際の挙動については、<cmath> を参照。
#include <iostream>
#include <cmath>
void test(double x, double y)
{
int quo = 0;
double rem = std::remquo(x, y, &quo);
std::cout << "remquo(" << x << ", " << y << ") = "
<< "quotient:" << quo
<< " remainder:" << rem << std::endl;
}
int main()
{
test(5.0, 2.0);
test(6.0, 4.0);
test(6.3, 3.0);
test(6.3, -3.0);
test(-6.3, 3.0);
test(-6.3, -3.0);
test(6.3, 3.15);
test(6.0, 2.0);
}- std::remquo[color ff0000]
remquo(5, 2) = quotient:2 remainder:1
remquo(6, 4) = quotient:2 remainder:-2
remquo(6.3, 3) = quotient:2 remainder:0.3
remquo(6.3, -3) = quotient:-2 remainder:0.3
remquo(-6.3, 3) = quotient:-2 remainder:-0.3
remquo(-6.3, -3) = quotient:2 remainder:-0.3
remquo(6.3, 3.15) = quotient:2 remainder:0
remquo(6, 2) = quotient:3 remainder:0
- C++11
- Clang, C++11 mode: 3.0
- GCC, C++11 mode: 4.3
- ICC: ??
- Visual C++: ??