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
|
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This file is part of the SourceMod/SourcePawn SDK.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#if defined _float_included
#endinput
#endif
#define _float_included
/**
* Converts an integer into a floating point value.
*
* @param value Integer to convert.
* @return Floating point value.
*/
native Float:float(value);
/**
* Multiplies two floats together.
*
* @param oper1 First value.
* @param oper2 Second value.
* @return oper1*oper2.
*/
native Float:FloatMul(Float:oper1, Float:oper2);
/**
* Divides the dividend by the divisor.
*
* @param dividend First value.
* @param divisor Second value.
* @return dividend/divisor.
*/
native Float:FloatDiv(Float:dividend, Float:divisor);
/**
* Adds two floats together.
*
* @param oper1 First value.
* @param oper2 Second value.
* @return oper1+oper2.
*/
native Float:FloatAdd(Float:oper1, Float:oper2);
/**
* Subtracts oper2 from oper1.
*
* @param oper1 First value.
* @param oper2 Second value.
* @return oper1-oper2.
*/
native Float:FloatSub(Float:oper1, Float:oper2);
/**
* Returns the decimal part of a float.
*
* @param value Input value.
* @return Decimal part.
*/
native Float:FloatFraction(Float:value);
/**
* Rounds a float to the closest integer to zero.
*
* @param value Input value to be rounded.
* @return Rounded value.
*/
native RoundToZero(Float:value);
/**
* Rounds a float to the next highest integer value.
*
* @param value Input value to be rounded.
* @return Rounded value.
*/
native RoundToCeil(Float:value);
/**
* Rounds a float to the next lowest integer value.
*
* @param value Input value to be rounded.
* @return Rounded value.
*/
native RoundToFloor(Float:value);
/**
* Standard IEEE rounding.
*
* @param value Input value to be rounded.
* @return Rounded value.
*/
native RoundToNearest(Float:value);
/**
* Compares two floats.
*
* @param fOne First value.
* @param fTwo Second value.
* @return Returns 1 if the first argument is greater than the second argument.
* Returns -1 if the first argument is smaller than the second argument.
* Returns 0 if both arguments are equal.
*/
native FloatCompare(Float:fOne, Float:fTwo);
/**
* Returns the square root of the input value, equivalent to floatpower(value, 0.5).
*
* @param value Input value.
* @return Square root of the value.
*/
native Float:SquareRoot(Float:value);
/**
* Returns the value raised to the power of the exponent.
*
* @param value Value to be raised.
* @param exponent Value to raise the base.
* @return value^exponent.
*/
native Float:Pow(Float:value, Float:exponent);
/**
* Returns the value of raising the input by e.
*
* @param value Input value.
* @return exp(value).
*/
native Float:Exponential(Float:value);
/**
* Returns the logarithm of any base specified.
*
* @param value Input value.
* @param base Logarithm base to use, default is 10.
* @return log(value)/log(base).
*/
native Float:Logarithm(Float:value, Float:base=10.0);
/**
* Returns the sine of the argument.
*
* @param value Input value in radians.
* @return sin(value).
*/
native Float:Sine(Float:value);
/**
* Returns the cosine of the argument.
*
* @param value Input value in radians.
* @return cos(value).
*/
native Float:Cosine(Float:value);
/**
* Returns the tangent of the argument.
*
* @param value Input value in radians.
* @return tan(value).
*/
native Float:Tangent(Float:value);
/**
* Returns an absolute value.
*
* @param value Input value.
* @return Absolute value of the input.
*/
native Float:FloatAbs(Float:value);
/**
* Returns the arctangent of the input value.
*
* @param angle Input value.
* @return atan(value) in radians.
*/
native Float:ArcTangent(Float:angle);
/**
* Returns the arccosine of the input value.
*
* @param angle Input value.
* @return acos(value) in radians.
*/
native Float:ArcCosine(Float:angle);
/**
* Returns the arcsine of the input value.
*
* @param angle Input value.
* @return asin(value) in radians.
*/
native Float:ArcSine(Float:angle);
/**
* Returns the arctangent2 of the input values.
*
* @param x Horizontal value.
* @param y Vertical value.
* @return atan2(value) in radians.
*/
native Float:ArcTangent2(Float:x, Float:y);
/**
* Rounds a floating point number using the "round to nearest" algorithm.
*
* @param value Floating point value to round.
* @return The value rounded to the nearest integer.
*/
stock RoundFloat(Float:value)
{
return RoundToNearest(value);
}
/**
* User defined operators.
*
*/
#pragma rational Float
native bool:__FLOAT_GT__(Float:a, Float:b);
native bool:__FLOAT_GE__(Float:a, Float:b);
native bool:__FLOAT_LT__(Float:a, Float:b);
native bool:__FLOAT_LE__(Float:a, Float:b);
native bool:__FLOAT_EQ__(Float:a, Float:b);
native bool:__FLOAT_NE__(Float:a, Float:b);
native bool:__FLOAT_NOT__(Float:a);
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 bool:operator!(Float:oper1) = __FLOAT_NOT__;
native bool:operator>(Float:oper1, Float:oper2) = __FLOAT_GT__;
native bool:operator>=(Float:oper1, Float:oper2) = __FLOAT_GE__;
native bool:operator<(Float:oper1, Float:oper2) = __FLOAT_LT__;
native bool:operator<=(Float:oper1, Float:oper2) = __FLOAT_LE__;
native bool:operator!=(Float:oper1, Float:oper2) = __FLOAT_NE__;
native bool:operator==(Float:oper1, Float:oper2) = __FLOAT_EQ__;
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, oper2)
{
return __FLOAT_EQ__(oper1, float(oper2));
}
stock bool:operator!=(Float:oper1, oper2)
{
return __FLOAT_NE__(oper1, float(oper2));
}
stock bool:operator>(Float:oper1, oper2)
{
return __FLOAT_GT__(oper1, float(oper2));
}
stock bool:operator>(oper1, Float:oper2)
{
return __FLOAT_GT__(float(oper1), oper2);
}
stock bool:operator>=(Float:oper1, oper2)
{
return __FLOAT_GE__(oper1, float(oper2));
}
stock bool:operator>=(oper1, Float:oper2)
{
return __FLOAT_GE__(float(oper1), oper2);
}
stock bool:operator<(Float:oper1, oper2)
{
return __FLOAT_LT__(oper1, float(oper2));
}
stock bool:operator<(oper1, Float:oper2)
{
return __FLOAT_LT__(float(oper1), oper2);
}
stock bool:operator<=(Float:oper1, oper2)
{
return __FLOAT_LE__(oper1, float(oper2));
}
stock bool:operator<=(oper1, Float:oper2)
{
return __FLOAT_LE__(float(oper1), oper2);
}
/**
* Forbidden operators.
*
*/
forward operator%(Float:oper1, Float:oper2);
forward operator%(Float:oper1, oper2);
forward operator%(oper1, Float:oper2);
#define FLOAT_PI 3.1415926535897932384626433832795
/**
* Converts degrees to radians.
*
* @param angle Degrees.
* @return Radians.
*/
stock Float:DegToRad(Float:angle)
{
return (angle*FLOAT_PI)/180;
}
/**
* Converts degrees to radians.
*
* @param angle Radians.
* @return Degrees.
*/
stock Float:RadToDeg(Float:angle)
{
return (angle*180)/FLOAT_PI;
}
/**
* Returns a random integer in the range [0, 2^31-1].
*
* Note: Uniform random number streams are seeded automatically per-plugin.
*
* @return Random integer.
*/
native GetURandomInt();
/**
* Returns a uniform random float in the range [0, 1).
*
* Note: Uniform random number streams are seeded automatically per-plugin.
*
* @return Uniform random floating-point number.
*/
native Float:GetURandomFloat();
/**
* Seeds a plugin's uniform random number stream. This is done automatically,
* so normally it is totally unnecessary to call this.
*
* @param seeds Array of numbers to use as seeding data.
* @param numSeeds Number of seeds in the seeds array.
* @noreturn
*/
native SetURandomSeed(const seeds[], numSeeds);
/**
* Seeds a plugin's uniform random number stream. This is done automatically,
* so normally it is totally unnecessary to call this.
*
* @param seed Single seed value.
* @noreturn
*/
stock SetURandomSeedSimple(seed)
{
new seeds[1];
seeds[0] = seed;
SetURandomSeed(seeds, 1);
}
|