chore: Arith placeholder.
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
extern int Arith_max(int x, int y);
|
||||||
|
extern int Arith_min(int x, int y);
|
||||||
|
extern int Arith_div(int x, int y);
|
||||||
|
extern int Arith_mod(int x, int y);
|
||||||
|
extern int Arith_ceiling(int x, int y);
|
||||||
|
extern int Arith_floor (int x, int y);
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
#include "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 (/* division truncates toward 0 */ -13/5 == -2
|
||||||
|
&& /* x and y have different signs */ (x < 0) != (y < 0)
|
||||||
|
&& x%y != 0)
|
||||||
|
return x/y - 1;
|
||||||
|
else
|
||||||
|
return x/y;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Arith_mod(int x, int y) {
|
||||||
|
return x - y*Arith_div(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Arith_floor(int x, int y) {
|
||||||
|
return Arith_div(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Arith_ceiling(int x, int y) {
|
||||||
|
return Arith_div(x, y) + (x%y != 0);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user