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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/#
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
#/
# ABS functions
/; abs (int a) [int]
/; if (a < 0)
;return -a
;/
;return a
;/
/; abs_f (float a) [float]
/; if (a < 0)
;return -a
;/
;return a
;/
/; abs_t (type T, T a) [T]
/; if ( a < (0)[T] )
;return -a
;/
;return a
;/
# Div funcs
/; div (int a, b) [int, int]
;int o1 = a / b, o2 = a % b
;return o1, o2
;/
/; div_f (float a, b) [float, float]
;float o1 = a / b, o2 = a % b
;return o1, o2
;/
/; div_t (type T, T a, b) [T, T]
;T o1 = a / b, o2 = a % b
;return o1, o2
;/
# Min/Max functions
/; max (int a, b) [int]
/; if (a > b)
;return a
;/
;return b
;/
/; max_f (float a, b) [float]
/; if (a > b)
;return a
;/
;return b
;/
/; max_t (type T, T a, b) [T]
/; if (a > b)
;return a
;/
;return b
;/
/; min (int a, b) [int]
/; if (a < b)
;return a
;/
;return b
;/
/; min_f (float a, b) [float]
/; if (a > b)
;return a
;/
;return b
;/
/; min_t (type T, T a, b) [T]
/; if (a < b)
;return a
;/
;return b
;/
# Float rounding
/; trunc (float a) [float]
;return a - (a % 1.0)
;/
/; trunc_t (type T, T a) [T]
;return a - (a % (1.0)[T])
;/
/; ceil (float a) [float]
/; if (trunc(a) !== a)
;return trunc(a + 1.0)
;/
;return a
;/
/; ceil_t (type T, T a) [T]
/; if (trunc_t(T, a) !== a)
;return trunc_t(T, a + (1.0)[T])
;/
;return a
;/
/; floor (float a) [float]
/; if (trunc(a) !== a)
;return trunc(a - 1.0)
;/
;return a
;/
/; floor_t (type T, T a) [T]
/; if (trunc_t(T, a) !== a)
;return trunc_t(T, a - (1.0)[T])
;/
;return a
;/
/; round (float a) [float]
/; if (a % 1.0 < 0.5)
;return floor(a)
;/
;return ceil(a)
;/
/; round_t (type T, T a) [T]
/; if (a % (1.0)[T] < (0.5)[T])
;return floor_t(T, a)
;/
;return ceil_t(T, a)
;/
|