Commit afc3077f authored by Alexander A. Maly's avatar Alexander A. Maly

Fix div bug

Issue #4 fixed.
parent 93739ea9
Pipeline #740 passed with stages
in 4 minutes and 21 seconds
......@@ -511,34 +511,33 @@ public:
static real maxreal() { return 1.7976931348623157e+308; }
inline static int div(int a, int b) {
if (b<=0) {
Core::abort(Core::fromUtf8("Деление на не натуральное число"));
static int div(int a, int b)
{
if (b <= 0) {
Core::abort(L"Деление на ненатуральное число");
return 0;
} else {
int aa = a;
if (aa<0) {
unsigned int absolunta = -1*(aa);
unsigned int quoti = absolunta / b + 1;
aa += quoti * b;
}
int m = aa % b;
return (a-m)/b;
}
int q = a / b, r = a % b;
if (r < 0)
q--;
return q;
}
inline static int mod(int a, int b) {
if (b<=0) {
Core::abort(Core::fromUtf8("Деление на не натуральное число"));
static int mod(int a, int b)
{
if (b <= 0) {
Core::abort(L"Деление на ненатуральное число");
return 0;
} else {
if (a<0) {
unsigned int absolunta = -1*(a);
unsigned int quoti = absolunta / b + 1;
a += quoti * b;
}
return a % b;
}
int r = a % b;
if (r < 0)
r += b;
return r;
}
template <typename T> static int sign(T x) {
if (x>0) return 1;
else if (x<0) return -1;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment