-
Notifications
You must be signed in to change notification settings - Fork 0
/
float.inc
285 lines (237 loc) · 11.9 KB
/
float.inc
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* Float arithmetic
*
* (c) Copyright 1999, Artran, Inc.
* Written by Greg Garner ([email protected])
* Modified in March 2001 to include user defined
* operators for the floating point functions.
*
* This file is provided as is (no warranties).
*/
#if defined _Float_included
#endinput
#endif
#define _Float_included
#pragma library Float
/* Different methods of rounding */
enum floatround_method {
floatround_round,
floatround_floor,
floatround_ceil,
floatround_tozero,
floatround_unbiased
}
enum anglemode {
radian,
degrees,
grades
}
/// <summary>Converts an integer into a float.</summary>
/// <param name="value">Integer value to convert to a float</param>
/// <seealso name="floatround"/>
/// <seealso name="floatstr"/>
/// <returns>The given integer as a float.</returns>
native Float:float(value);
/// <summary>Converts a string to a float.</summary>
/// <param name="string">The string to convert into a float</param>
/// <seealso name="floatround"/>
/// <seealso name="float"/>
/// <returns>The requested float value.</returns>
native Float:floatstr(const string[]);
/// <summary>Multiplies two floats with each other.</summary>
/// <param name="oper1">First Float</param>
/// <param name="oper2">Second Float, the first one gets multiplied with</param>
/// <seealso name="Floatadd"/>
/// <seealso name="Floatsub"/>
/// <seealso name="Floatdiv"/>
/// <returns>The product of the two given floats.</returns>
native Float:floatmul(Float:oper1, Float:oper2);
/// <summary>Divide one float by another one. Redundant as the division operator (/) does the same thing.</summary>
/// <param name="dividend">First float</param>
/// <param name="divisor">Second float (dividates the first float.)</param>
/// <seealso name="floatadd"/>
/// <seealso name="floatsub"/>
/// <seealso name="floatmul"/>
/// <returns>The quotient of the two given floats.</returns>
native Float:floatdiv(Float:dividend, Float:divisor);
/// <summary>Adds two floats together. This function is redundant as the standard operator (+) does the same thing.</summary>
/// <param name="oper1">First float</param>
/// <param name="oper2">Second float</param>
/// <seealso name="Floatsub"/>
/// <seealso name="Floatmul"/>
/// <seealso name="Floatdiv"/>
/// <returns>The sum of the two given floats.</returns>
native Float:floatadd(Float:oper1, Float:oper2);
/// <summary>Subtracts one float from another one. Note that this function has no real use, as one can simply use the standard operator (-) instead.</summary>
/// <param name="oper1">First Float</param>
/// <param name="oper2">Second Float (gets subtracted from the first float.)</param>
/// <seealso name="Floatadd"/>
/// <seealso name="Floatmul"/>
/// <seealso name="Floatdiv"/>
/// <returns>The difference of the two given floats.</returns>
native Float:floatsub(Float:oper1, Float:oper2);
/// <summary>Get the fractional part of a float. This means the value of the numbers after the decimal point.</summary>
/// <param name="value">The float to get the fractional part of</param>
/// <seealso name="floatround"/>
/// <returns>The fractional part of the float, as a float value.</returns>
native Float:floatfract(Float:value);
/// <summary>Round a floating point number to an integer value.</summary>
/// <param name="value">The value to round</param>
/// <param name="method">The floatround method to use (optional=<b><c>floatround_round</c></b>)</param>
/// <seealso name="float"/>
/// <seealso name="floatstr"/>
/// <remarks>
/// <b>Rounding methods:</b><p/>
/// <ul>
/// <li><b><c>floatround_round</c></b> - round to the nearest integer. A fractional part of exactly 0.5 rounds upwards (this is the default).</li>
/// <li><b><c>floatround_floor</c></b> - round downwards.</li>
/// <li><b><c>floatround_ceil</c></b> - round upwards.</li>
/// <li><b><c>floatround_tozero</c></b> - round downwards for positive values and upwards for negative values ("truncate").</li>
/// </ul>
/// </remarks>
/// <returns>The rounded value as an integer.</returns>
native floatround(Float:value, floatround_method:method=floatround_round);
/// <summary>floatcmp can be used to compare float values to each other, to validate the comparison.</summary>
/// <param name="oper1">The first float value to compare</param>
/// <param name="oper2">The second float value to compare</param>
/// <returns><b><c>0</c></b> if value does match, <b><c>1</c></b> if the first value is bigger and <b><c>-1</c></b> if the 2nd value is bigger.</returns>
native floatcmp(Float:oper1, Float:oper2);
/// <summary>Calculates the square root of given value.</summary>
/// <param name="value">The value to calculate the square root of</param>
/// <seealso name="floatpower"/>
/// <seealso name="floatlog"/>
/// <remarks>This function raises a "domain" error if the input value is negative. You may use <a href="#floatabs">floatabs</a> to get the absolute (positive) value.</remarks>
/// <returns>The square root of the input value, as a float.</returns>
native Float:floatsqroot(Float:value);
/// <summary>Raises the given value to the power of the exponent.</summary>
/// <param name="value">The value to raise to a power, as a floating-point number</param>
/// <param name="exponent">The exponent is also a floating-point number. It may be zero or negative</param>
/// <seealso name="floatsqroot"/>
/// <seealso name="floatlog"/>
/// <returns>The result of 'value' to the power of 'exponent'.</returns>
native Float:floatpower(Float:value, Float:exponent);
/// <summary>This function allows you to get the logarithm of a float value.</summary>
/// <param name="value">The value of which to get the logarithm</param>
/// <param name="base">The logarithm base (optional=<b><c>10.0</c></b>)</param>
/// <seealso name="floatsqroot"/>
/// <seealso name="floatpower"/>
/// <returns>The logarithm as a float value.</returns>
native Float:floatlog(Float:value, Float:base=10.0);
/// <summary>Get the sine from a given angle. The input angle may be in radians, degrees or grades.</summary>
/// <param name="value">The angle from which to get the sine</param>
/// <param name="mode">The angle mode (see below) to use, depending on the value entered (optional=<b><c>radian</c></b>)</param>
/// <seealso name="floattan"/>
/// <seealso name="floatcos"/>
/// <remarks>GTA/SA-MP use <b>degrees</b> for angles in most circumstances, for example <a href="#GetPlayerFacingAngle">GetPlayerFacingAngle</a>. Therefore, it is most likely you'll want to use the <b>degrees</b> angle mode, not radians. </remarks>
/// <remarks>Also note that angles in GTA are counterclockwise; 270° is East and 90° is West. South is still 180° and North still 0°/360°. </remarks>
/// <remarks>
/// <b>Angle modes:</b><p/>
/// <ul>
/// <li>radian</li>
/// <li>degrees</li>
/// <li>grades </li>
/// </ul>
/// </remarks>
/// <returns>The sine of the value entered.</returns>
native Float:floatsin(Float:value, anglemode:mode=radian);
/// <summary>Get the cosine from a given angle. The input angle may be in radians, degrees or grades.</summary>
/// <param name="value">The angle from which to get the cosine</param>
/// <param name="mode">The angle mode (see below) to use, depending on the value entered (optional=<b><c>radian</c></b>)</param>
/// <seealso name="floatsin"/>
/// <seealso name="floattan"/>
/// <remarks>GTA/SA-MP use <b>degrees</b> for angles in most circumstances, for example <a href="#GetPlayerFacingAngle">GetPlayerFacingAngle</a>. Therefore, it is most likely you'll want to use the <b>degrees</b> angle mode, not radians. </remarks>
/// <remarks>Also note that angles in GTA are counterclockwise; 270° is East and 90° is West. South is still 180° and North still 0°/360°. </remarks>
/// <remarks>
/// <b>Angle modes:</b><p/>
/// <ul>
/// <li>radian</li>
/// <li>degrees</li>
/// <li>grades </li>
/// </ul>
/// </remarks>
/// <returns>The cosine of the value entered.</returns>
native Float:floatcos(Float:value, anglemode:mode=radian);
/// <summary>Get the tangent from a given angle. The input angle may be in radians, degrees or grades.</summary>
/// <param name="value">The angle from which to get the tangent</param>
/// <param name="mode">The angle mode to use, depending on the value entered</param>
/// <seealso name="floatsin"/>
/// <seealso name="floatcos"/>
/// <remarks>GTA/SA-MP use <b>degrees</b> for angles in most circumstances, for example <a href="#GetPlayerFacingAngle">GetPlayerFacingAngle</a>. Therefore, it is most likely you'll want to use the <b>degrees</b> angle mode, not radians. </remarks>
/// <remarks>Also note that angles in GTA are counterclockwise; 270° is East and 90° is West. South is still 180° and North still 0°/360°. </remarks>
/// <remarks>
/// <b>Angle modes:</b><p/>
/// <ul>
/// <li>radian</li>
/// <li>degrees</li>
/// <li>grades </li>
/// </ul>
/// </remarks>
/// <returns>The tangent from the value entered.</returns>
native Float:floattan(Float:value, anglemode:mode=radian);
/// <summary>This function returns the absolute value of float.</summary>
/// <param name="value">The float value to get the absolute value of</param>
/// <returns>The absolute value of the float (as a float value).</returns>
native Float:floatabs(Float:value);
/**************************************************/
#pragma rational Float
/* user defined operators */
native Float:operator*(Float:oper1, Float:oper2) = floatmul;
native Float:operator/(Float:oper1, Float:oper2) = floatdiv;
native Float:operator+(Float:oper1, Float:oper2) = floatadd;
native Float:operator-(Float:oper1, Float:oper2) = floatsub;
native Float:operator=(oper) = float;
stock Float:operator++(Float:oper)
return oper+1.0;
stock Float:operator--(Float:oper)
return oper-1.0;
stock Float:operator-(Float:oper)
return oper^Float:cellmin; /* IEEE values are sign/magnitude */
stock Float:operator*(Float:oper1, oper2)
return floatmul(oper1, float(oper2)); /* "*" is commutative */
stock Float:operator/(Float:oper1, oper2)
return floatdiv(oper1, float(oper2));
stock Float:operator/(oper1, Float:oper2)
return floatdiv(float(oper1), oper2);
stock Float:operator+(Float:oper1, oper2)
return floatadd(oper1, float(oper2)); /* "+" is commutative */
stock Float:operator-(Float:oper1, oper2)
return floatsub(oper1, float(oper2));
stock Float:operator-(oper1, Float:oper2)
return floatsub(float(oper1), oper2);
stock bool:operator==(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) == 0;
stock bool:operator==(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) == 0; /* "==" is commutative */
stock bool:operator!=(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) != 0;
stock bool:operator!=(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) != 0; /* "!=" is commutative */
stock bool:operator>(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) > 0;
stock bool:operator>(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) > 0;
stock bool:operator>(oper1, Float:oper2)
return floatcmp(float(oper1), oper2) > 0;
stock bool:operator>=(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) >= 0;
stock bool:operator>=(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) >= 0;
stock bool:operator>=(oper1, Float:oper2)
return floatcmp(float(oper1), oper2) >= 0;
stock bool:operator<(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) < 0;
stock bool:operator<(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) < 0;
stock bool:operator<(oper1, Float:oper2)
return floatcmp(float(oper1), oper2) < 0;
stock bool:operator<=(Float:oper1, Float:oper2)
return floatcmp(oper1, oper2) <= 0;
stock bool:operator<=(Float:oper1, oper2)
return floatcmp(oper1, float(oper2)) <= 0;
stock bool:operator<=(oper1, Float:oper2)
return floatcmp(float(oper1), oper2) <= 0;
stock bool:operator!(Float:oper)
return (_:oper & cellmax) == 0;
/* forbidden operations */
forward operator%(Float:oper1, Float:oper2);
forward operator%(Float:oper1, oper2);
forward operator%(oper1, Float:oper2);