Skip to content

Commit

Permalink
cii: Add arith impl
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 30, 2023
1 parent 02aafb8 commit 9a7a1a4
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion cii/src/arith.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@
// Use of this source is governed by GNU General Public License
// that can be found in the LICENSE file.

#include "cii/arith.h"
#include "cii/arith.h"

int arith_max(int x, int y) {
return (x > y) ? x : y;
}

int arith_min(int x, int y) {
return (x > y) ? y : x;
}

int arith_div(int x, int y) {
if ((-13 / 5 == -2) && ((x < 0) != (y < 0)) && (x % y != 0)) {
return x / y - 1;
} else {
return x / y;
}
}

int arith_mod(int x, int y) {
if ((-13 / 5 == -2) && ((x < 0) != (y < 0)) && (x % y != 0)) {
return x % y + y;
} else {
return x % y;
}
}

int arith_ceiling(int x, int y) {
return arith_div(x, y) + ( x % y != 0);
}

int arith_floor(int x, int y) {
return arith_div(x, y);
}

0 comments on commit 9a7a1a4

Please sign in to comment.