-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathfloat.inc
executable file
·532 lines (475 loc) · 14.2 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
#if defined _Float_included
#endinput
#endif
#define _Float_included
/**
* <library name="time" summary="Float arithmetic.">
* <license>
* (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).
* </license>
* <summary pawndoc="true">
* This library uses the enhanced <em>pawndoc.xsl</em> from
* <a href="https://github.com/pawn-lang/pawndoc">pawn-lang/pawndoc</a>.
* This XSL has features such as library and markdown support, and will not
* render this message when used.
* </summary>
* </library>
*/
#pragma library Float
#pragma rational Float
/// <p/>
/**
* <library>float</library>
* <summary>Different methods of rounding.</summary>
*/
enum floatround_method
{
floatround_round,
floatround_floor,
floatround_ceil,
floatround_tozero,
floatround_unbiased
}
static stock floatround_method:_@floatround_method() { return floatround_method; }
/// <p/>
/**
* <library>float</library>
*/
enum anglemode
{
radian,
degrees,
grades
}
static stock anglemode:_@anglemode() { return anglemode; }
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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[]);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/**
* <library>float</library>
* <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);
/* user defined operators */
/**
* <library>float</library>
*/
native Float:operator*(Float:oper1, Float:oper2) = floatmul;
/**
* <library>float</library>
*/
native Float:operator/(Float:oper1, Float:oper2) = floatdiv;
/**
* <library>float</library>
*/
native Float:operator+(Float:oper1, Float:oper2) = floatadd;
/**
* <library>float</library>
*/
native Float:operator-(Float:oper1, Float:oper2) = floatsub;
/**
* <library>float</library>
*/
native Float:operator=(oper) = float;
/**
* <library>float</library>
*/
stock Float:operator++(Float:oper)
{
return oper + 1.0;
}
/**
* <library>float</library>
*/
stock Float:operator--(Float:oper)
{
return oper - 1.0;
}
/**
* <library>float</library>
*/
stock Float:operator-(Float:oper)
{
return oper ^ Float:cellmin; /* IEEE values are sign/magnitude */
}
/**
* <library>float</library>
*/
stock Float:operator*(Float:oper1, oper2)
{
return floatmul(oper1, float(oper2)); /* "*" is commutative */
}
/**
* <library>float</library>
*/
stock Float:operator/(Float:oper1, oper2)
{
return floatdiv(oper1, float(oper2));
}
/**
* <library>float</library>
*/
stock Float:operator/(oper1, Float:oper2)
{
return floatdiv(float(oper1), oper2);
}
/**
* <library>float</library>
*/
stock Float:operator+(Float:oper1, oper2)
{
return floatadd(oper1, float(oper2)); /* "+" is commutative */
}
/**
* <library>float</library>
*/
stock Float:operator-(Float:oper1, oper2)
{
return floatsub(oper1, float(oper2));
}
/**
* <library>float</library>
*/
stock Float:operator-(oper1, Float:oper2)
{
return floatsub(float(oper1), oper2);
}
/**
* <library>float</library>
*/
stock bool:operator==(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) == 0;
}
/**
* <library>float</library>
*/
stock bool:operator==(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) == 0; /* "==" is commutative */
}
/**
* <library>float</library>
*/
stock bool:operator!=(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) != 0;
}
/**
* <library>float</library>
*/
stock bool:operator!=(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) != 0; /* "!=" is commutative */
}
/**
* <library>float</library>
*/
stock bool:operator>(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) > 0;
}
/**
* <library>float</library>
*/
stock bool:operator>(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) > 0;
}
/**
* <library>float</library>
*/
stock bool:operator>(oper1, Float:oper2)
{
return floatcmp(float(oper1), oper2) > 0;
}
/**
* <library>float</library>
*/
stock bool:operator>=(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) >= 0;
}
/**
* <library>float</library>
*/
stock bool:operator>=(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) >= 0;
}
/**
* <library>float</library>
*/
stock bool:operator>=(oper1, Float:oper2)
{
return floatcmp(float(oper1), oper2) >= 0;
}
/**
* <library>float</library>
*/
stock bool:operator<(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) < 0;
}
/**
* <library>float</library>
*/
stock bool:operator<(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) < 0;
}
/**
* <library>float</library>
*/
stock bool:operator<(oper1, Float:oper2)
{
return floatcmp(float(oper1), oper2) < 0;
}
/**
* <library>float</library>
*/
stock bool:operator<=(Float:oper1, Float:oper2)
{
return floatcmp(oper1, oper2) <= 0;
}
/**
* <library>float</library>
*/
stock bool:operator<=(Float:oper1, oper2)
{
return floatcmp(oper1, float(oper2)) <= 0;
}
/**
* <library>float</library>
*/
stock bool:operator<=(oper1, Float:oper2)
{
return floatcmp(float(oper1), oper2) <= 0;
}
/**
* <library>float</library>
*/
stock bool:operator!(Float:oper)
{
return (_:oper & cellmax) == 0;
}
/* forbidden operations */
/**
* <library>float</library>
*/
forward operator%(Float:oper1, Float:oper2);
/**
* <library>float</library>
*/
forward operator%(Float:oper1, oper2);
/**
* <library>float</library>
*/
forward operator%(oper1, Float:oper2);