#include <iostream>
#include <cmath>
using namespace std;
double my_remainder(double Value1, double Value2)
{
const double Result = fmod(Value1, Value2);
return Value2 < 0.0 ? -Result : Result;
}
void test(double a, double b)
{
double res1 = my_remainder(a, b);
double res2 = remainder(a, b);
std::cout << a << "/" << b << "\n"
<< " impl: " << res1 << "\n"
<< " std: " << res2 << "\n"
<< ((res1 == res2) ? " pass\n" : " fail\n");
}
int main()
{
test(5.3, 2);
test(18.5, 4.2);
test(-5.3, 2);
test(-18.5, 4.2);
test(5.3, -2);
test(18.5, -4.2);
test(-5.3, -2);
test(-18.5, -4.2);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKZG91YmxlIG15X3JlbWFpbmRlcihkb3VibGUgVmFsdWUxLCBkb3VibGUgVmFsdWUyKQp7CiAgICBjb25zdCBkb3VibGUgUmVzdWx0ID0gZm1vZChWYWx1ZTEsIFZhbHVlMik7CiAgICByZXR1cm4gVmFsdWUyIDwgMC4wID8gLVJlc3VsdCA6IFJlc3VsdDsKfQogICAgCnZvaWQgdGVzdChkb3VibGUgYSwgZG91YmxlIGIpCnsKCWRvdWJsZSByZXMxID0gbXlfcmVtYWluZGVyKGEsIGIpOwoJZG91YmxlIHJlczIgPSByZW1haW5kZXIoYSwgYik7CgkKCXN0ZDo6Y291dCA8PCBhIDw8ICIvIiA8PCBiIDw8ICJcbiIKCQk8PCAiIGltcGw6ICIgPDwgcmVzMSA8PCAiXG4iCgkJPDwgIiAgc3RkOiAiIDw8IHJlczIgPDwgIlxuIgoJCTw8ICgocmVzMSA9PSByZXMyKSA/ICIgcGFzc1xuIiA6ICIgZmFpbFxuIik7Cn0KCgoKaW50IG1haW4oKQp7Cgl0ZXN0KDUuMywgMik7Cgl0ZXN0KDE4LjUsIDQuMik7Cgl0ZXN0KC01LjMsIDIpOwoJdGVzdCgtMTguNSwgNC4yKTsKCXRlc3QoNS4zLCAtMik7Cgl0ZXN0KDE4LjUsIC00LjIpOwoJdGVzdCgtNS4zLCAtMik7Cgl0ZXN0KC0xOC41LCAtNC4yKTsKfQ==