-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtml_parser_arith.c
More file actions
57 lines (46 loc) · 825 Bytes
/
Copy pathhtml_parser_arith.c
File metadata and controls
57 lines (46 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "html_parser_arith.h"
static int trunc_to_zero(int x, int y)
{
int z;
if (((x < 0) != (y < 0)) && (y < 0)) {
int t = y;
y = x;
x = t;
}
z = x / y;
return (z * y > x);
}
extern int Arith_max(int x, int y)
{
return (x > y ? x : y);
}
extern int Arith_min(int x, int y)
{
return (x < y ? x : y);
}
extern int Arith_div(int x, int y)
{
int z;
z = x / y;
if ((trunc_to_zero(x, y)) && ((x < 0) != (y < 0)) && (x % y != 0)) {
return (x / y - 1);
} else {
return (x / y);
}
}
extern int Arith_mod(int x, int y)
{
if ((trunc_to_zero(x, y)) && ((x < 0) != (y < 0)) && (x % y != 0)) {
return (x % y + y);
} else {
return (x % y);
}
}
extern int Arith_ceiling(int x, int y)
{
return (Arith_div(x, y) + (x % y != 0));
}
extern int Arith_floor(int x, int y)
{
return (Arith_div(x,y));
}