plugins/include/float.inc
author Scott Ehlert <ds@alliedmods.net>
Sun Mar 30 07:00:22 2008 +0000 (2008-03-30)
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
permissions -rw-r--r--
Spring Cleaning, Part Ichi (1)
Various minor things done to project files
Updated sample extension project file and updated makefile to the new unified version (more changes likely on the way)
Updated regex project file and makefile
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     5
 * =============================================================================
ds@1952
     6
 *
ds@1952
     7
 * This file is part of the SourceMod/SourcePawn SDK.
ds@1952
     8
 *
ds@1952
     9
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
    10
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    11
 * Free Software Foundation.
ds@1952
    12
 * 
ds@1952
    13
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    15
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    16
 * details.
ds@1952
    17
 *
ds@1952
    18
 * You should have received a copy of the GNU General Public License along with
ds@1952
    19
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    20
 *
ds@1952
    21
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    22
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    23
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    24
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    25
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    26
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    27
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    28
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    29
 *
ds@1952
    30
 * Version: $Id$
ds@1952
    31
 */
ds@1952
    32
 
ds@1952
    33
#if defined _float_included
ds@1952
    34
 #endinput
ds@1952
    35
#endif
ds@1952
    36
#define _float_included
ds@1952
    37
ds@1952
    38
/**
ds@1952
    39
 * Converts an integer into a floating point value.
ds@1952
    40
 *
ds@1952
    41
 * @param value			Integer to convert.
ds@1952
    42
 * @return				Floating point value.
ds@1952
    43
 */
ds@1952
    44
native Float:float(value);
ds@1952
    45
ds@1952
    46
/**
ds@1952
    47
 * Multiplies two floats together.
ds@1952
    48
 *
ds@1952
    49
 * @param oper1			First value.
ds@1952
    50
 * @param oper2			Second value.
ds@1952
    51
 * @return				oper1*oper2.
ds@1952
    52
 */
ds@1952
    53
native Float:FloatMul(Float:oper1, Float:oper2);
ds@1952
    54
ds@1952
    55
/**
ds@1952
    56
 * Divides the dividend by the divisor.
ds@1952
    57
 *
ds@1952
    58
 * @param dividend		First value.
ds@1952
    59
 * @param divisor		Second value.
ds@1952
    60
 * @return				dividend/divisor.
ds@1952
    61
 */
ds@1952
    62
native Float:FloatDiv(Float:dividend, Float:divisor);
ds@1952
    63
ds@1952
    64
/**
ds@1952
    65
 * Adds two floats together.
ds@1952
    66
 *
ds@1952
    67
 * @param oper1			First value.
ds@1952
    68
 * @param oper2			Second value.
ds@1952
    69
 * @return				oper1+oper2.
ds@1952
    70
 */
ds@1952
    71
native Float:FloatAdd(Float:oper1, Float:oper2);
ds@1952
    72
ds@1952
    73
/**
ds@1952
    74
 * Subtracts oper2 from oper1.
ds@1952
    75
 *
ds@1952
    76
 * @param oper1			First value.
ds@1952
    77
 * @param oper2			Second value.
ds@1952
    78
 * @return				oper1-oper2.
ds@1952
    79
 */
ds@1952
    80
native Float:FloatSub(Float:oper1, Float:oper2);
ds@1952
    81
ds@1952
    82
/**
ds@1952
    83
 * Returns the decimal part of a float.
ds@1952
    84
 *
ds@1952
    85
 * @param value			Input value.
ds@1952
    86
 * @return				Decimal part.
ds@1952
    87
 */
ds@1952
    88
native Float:FloatFraction(Float:value);
ds@1952
    89
ds@1952
    90
/**
ds@1952
    91
 * Rounds a float to the closest integer to zero.
ds@1952
    92
 *
ds@1952
    93
 * @param value			Input value to be rounded.
ds@1952
    94
 * @return				Rounded value.
ds@1952
    95
 */
ds@1952
    96
native RoundToZero(Float:value);
ds@1952
    97
ds@1952
    98
/**
ds@1952
    99
 * Rounds a float to the next highest integer value.
ds@1952
   100
 *
ds@1952
   101
 * @param value			Input value to be rounded.
ds@1952
   102
 * @return				Rounded value.
ds@1952
   103
 */
ds@1952
   104
native RoundToCeil(Float:value);
ds@1952
   105
ds@1952
   106
/**
ds@1952
   107
 * Rounds a float to the next lowest integer value.
ds@1952
   108
 *
ds@1952
   109
 * @param value			Input value to be rounded.
ds@1952
   110
 * @return				Rounded value.
ds@1952
   111
 */
ds@1952
   112
native RoundToFloor(Float:value);
ds@1952
   113
ds@1952
   114
/**
ds@1952
   115
 * Standard IEEE rounding.
ds@1952
   116
 *
ds@1952
   117
 * @param value			Input value to be rounded.
ds@1952
   118
 * @return				Rounded value.
ds@1952
   119
 */
ds@1952
   120
native RoundToNearest(Float:value);
ds@1952
   121
ds@1952
   122
/**
ds@1952
   123
 * Compares two floats.
ds@1952
   124
 *
ds@1952
   125
 * @param fOne			First value.
ds@1952
   126
 * @param fTwo			Second value.
ds@1952
   127
 * @return				Returns 1 if the first argument is greater than the second argument.
ds@1952
   128
 *                      Returns -1 if the first argument is smaller than the second argument.
ds@1952
   129
 *                      Returns 0 if both arguments are equal.
ds@1952
   130
 */
ds@1952
   131
native FloatCompare(Float:fOne, Float:fTwo);
ds@1952
   132
ds@1952
   133
/**
ds@1952
   134
 * Returns the square root of the input value, equivalent to floatpower(value, 0.5).
ds@1952
   135
 *
ds@1952
   136
 * @param value			Input value.
ds@1952
   137
 * @return				Square root of the value.
ds@1952
   138
 */
ds@1952
   139
native Float:SquareRoot(Float:value);
ds@1952
   140
ds@1952
   141
/**
ds@1952
   142
 * Returns the value raised to the power of the exponent.
ds@1952
   143
 *
ds@1952
   144
 * @param value			Value to be raised.
ds@1952
   145
 * @param exponent		Value to raise the base.
ds@1952
   146
 * @return				value^exponent.
ds@1952
   147
 */
ds@1952
   148
native Float:Pow(Float:value, Float:exponent);
ds@1952
   149
ds@1952
   150
/**
ds@1952
   151
 * Returns the value of raising the input by e.
ds@1952
   152
 *
ds@1952
   153
 * @param value			Input value.
ds@1952
   154
 * @return				exp(value).
ds@1952
   155
 */
ds@1952
   156
native Float:Exponential(Float:value);
ds@1952
   157
ds@1952
   158
/**
ds@1952
   159
 * Returns the logarithm of any base specified.
ds@1952
   160
 *
ds@1952
   161
 * @param value			Input value.
ds@1952
   162
 * @param base			Logarithm base to use, default is 10.
ds@1952
   163
 * @return				log(value)/log(base).
ds@1952
   164
 */
ds@1952
   165
native Float:Logarithm(Float:value, Float:base=10.0);
ds@1952
   166
ds@1952
   167
/**
ds@1952
   168
 * Returns the sine of the argument.
ds@1952
   169
 *
ds@1952
   170
 * @param value			Input value in radians.
ds@1952
   171
 * @return				sin(value).
ds@1952
   172
 */
ds@1952
   173
native Float:Sine(Float:value);
ds@1952
   174
ds@1952
   175
/**
ds@1952
   176
 * Returns the cosine of the argument.
ds@1952
   177
 *
ds@1952
   178
 * @param value			Input value in radians.
ds@1952
   179
 * @return				cos(value).
ds@1952
   180
 */
ds@1952
   181
native Float:Cosine(Float:value);
ds@1952
   182
ds@1952
   183
/**
ds@1952
   184
 * Returns the tangent of the argument.
ds@1952
   185
 *
ds@1952
   186
 * @param value			Input value in radians.
ds@1952
   187
 * @return				tan(value).
ds@1952
   188
 */
ds@1952
   189
native Float:Tangent(Float:value);
ds@1952
   190
ds@1952
   191
/**
ds@1952
   192
 * Returns an absolute value.
ds@1952
   193
 *
ds@1952
   194
 * @param value			Input value.
ds@1952
   195
 * @return				Absolute value of the input.
ds@1952
   196
 */
ds@1952
   197
native Float:FloatAbs(Float:value);
ds@1952
   198
ds@1952
   199
/**
ds@1952
   200
 * Returns the arctangent of the input value.
ds@1952
   201
 *
ds@1952
   202
 * @param angle			Input value.
ds@1952
   203
 * @return				atan(value) in radians.
ds@1952
   204
 */
ds@1952
   205
native Float:ArcTangent(Float:angle);
ds@1952
   206
ds@1952
   207
/**
ds@1952
   208
 * Returns the arccosine of the input value.
ds@1952
   209
 *
ds@1952
   210
 * @param angle			Input value.
ds@1952
   211
 * @return				acos(value) in radians.
ds@1952
   212
 */
ds@1952
   213
native Float:ArcCosine(Float:angle);
ds@1952
   214
ds@1952
   215
/**
ds@1952
   216
 * Returns the arcsine of the input value.
ds@1952
   217
 *
ds@1952
   218
 * @param angle			Input value.
ds@1952
   219
 * @return				asin(value) in radians.
ds@1952
   220
 */
ds@1952
   221
native Float:ArcSine(Float:angle);
ds@1952
   222
ds@1952
   223
/**
ds@1952
   224
 * Returns the arctangent2 of the input values.
ds@1952
   225
 *
ds@1952
   226
 * @param x				Horizontal value.
ds@1952
   227
 * @param y				Vertical value.
ds@1952
   228
 * @return				atan2(value) in radians.
ds@1952
   229
 */
ds@1952
   230
native Float:ArcTangent2(Float:x, Float:y);
ds@1952
   231
ds@1952
   232
/**
ds@1952
   233
 * Rounds a floating point number using the "round to nearest" algorithm.
ds@1952
   234
 *
ds@1952
   235
 * @param value			Floating point value to round.
ds@1952
   236
 * @return				The value rounded to the nearest integer.
ds@1952
   237
 */
ds@1952
   238
stock RoundFloat(Float:value)
ds@1952
   239
{
ds@1952
   240
	return RoundToNearest(value);
ds@1952
   241
}
ds@1952
   242
ds@1952
   243
/**
ds@1952
   244
 * User defined operators.
ds@1952
   245
 *
ds@1952
   246
 */
ds@1952
   247
#pragma rational Float
ds@1952
   248
ds@1952
   249
native Float:operator*(Float:oper1, Float:oper2) = FloatMul;
ds@1952
   250
native Float:operator/(Float:oper1, Float:oper2) = FloatDiv;
ds@1952
   251
native Float:operator+(Float:oper1, Float:oper2) = FloatAdd;
ds@1952
   252
native Float:operator-(Float:oper1, Float:oper2) = FloatSub;
ds@1952
   253
ds@1952
   254
stock Float:operator++(Float:oper)
ds@1952
   255
{
ds@1952
   256
	return oper+1.0;
ds@1952
   257
}
ds@1952
   258
ds@1952
   259
stock Float:operator--(Float:oper)
ds@1952
   260
{
ds@1952
   261
	return oper-1.0;
ds@1952
   262
}
ds@1952
   263
ds@1952
   264
stock Float:operator-(Float:oper)
ds@1952
   265
{
ds@1952
   266
	return oper^Float:((-1)^((-1)/2));				/* IEEE values are sign/magnitude */
ds@1952
   267
}
ds@1952
   268
ds@1952
   269
stock Float:operator*(Float:oper1, oper2)
ds@1952
   270
{
ds@1952
   271
	return FloatMul(oper1, float(oper2));			/* "*" is commutative */
ds@1952
   272
}
ds@1952
   273
ds@1952
   274
stock Float:operator/(Float:oper1, oper2)
ds@1952
   275
{
ds@1952
   276
	return FloatDiv(oper1, float(oper2));
ds@1952
   277
}
ds@1952
   278
ds@1952
   279
stock Float:operator/(oper1, Float:oper2)
ds@1952
   280
{
ds@1952
   281
	return FloatDiv(float(oper1), oper2);
ds@1952
   282
}
ds@1952
   283
ds@1952
   284
stock Float:operator+(Float:oper1, oper2)
ds@1952
   285
{
ds@1952
   286
	return FloatAdd(oper1, float(oper2));			/* "+" is commutative */
ds@1952
   287
}
ds@1952
   288
ds@1952
   289
stock Float:operator-(Float:oper1, oper2)
ds@1952
   290
{
ds@1952
   291
	return FloatSub(oper1, float(oper2));
ds@1952
   292
}
ds@1952
   293
ds@1952
   294
stock Float:operator-(oper1, Float:oper2)
ds@1952
   295
{
ds@1952
   296
	return FloatSub(float(oper1), oper2);
ds@1952
   297
}
ds@1952
   298
ds@1952
   299
stock bool:operator==(Float:oper1, Float:oper2)
ds@1952
   300
{
ds@1952
   301
	return FloatCompare(oper1, oper2) == 0;
ds@1952
   302
}
ds@1952
   303
ds@1952
   304
stock bool:operator==(Float:oper1, oper2)
ds@1952
   305
{
ds@1952
   306
	return FloatCompare(oper1, float(oper2)) == 0; 	/* "==" is commutative */
ds@1952
   307
}
ds@1952
   308
ds@1952
   309
stock bool:operator!=(Float:oper1, Float:oper2)
ds@1952
   310
{
ds@1952
   311
	return FloatCompare(oper1, oper2) != 0;
ds@1952
   312
}
ds@1952
   313
ds@1952
   314
stock bool:operator!=(Float:oper1, oper2)
ds@1952
   315
{
ds@1952
   316
	return FloatCompare(oper1, float(oper2)) != 0; 	/* "==" is commutative */
ds@1952
   317
}
ds@1952
   318
ds@1952
   319
stock bool:operator>(Float:oper1, Float:oper2)
ds@1952
   320
{
ds@1952
   321
	return FloatCompare(oper1, oper2) > 0;
ds@1952
   322
}
ds@1952
   323
ds@1952
   324
stock bool:operator>(Float:oper1, oper2)
ds@1952
   325
{
ds@1952
   326
	return FloatCompare(oper1, float(oper2)) > 0;
ds@1952
   327
}
ds@1952
   328
ds@1952
   329
stock bool:operator>(oper1, Float:oper2)
ds@1952
   330
{
ds@1952
   331
	return FloatCompare(float(oper1), oper2) > 0;
ds@1952
   332
}
ds@1952
   333
ds@1952
   334
stock bool:operator>=(Float:oper1, Float:oper2)
ds@1952
   335
{
ds@1952
   336
	return FloatCompare(oper1, oper2) >= 0;
ds@1952
   337
}
ds@1952
   338
ds@1952
   339
stock bool:operator>=(Float:oper1, oper2)
ds@1952
   340
{
ds@1952
   341
	return FloatCompare(oper1, float(oper2)) >= 0;
ds@1952
   342
}
ds@1952
   343
ds@1952
   344
stock bool:operator>=(oper1, Float:oper2)
ds@1952
   345
{
ds@1952
   346
	return FloatCompare(float(oper1), oper2) >= 0;
ds@1952
   347
}
ds@1952
   348
ds@1952
   349
stock bool:operator<(Float:oper1, Float:oper2)
ds@1952
   350
{
ds@1952
   351
	return FloatCompare(oper1, oper2) < 0;
ds@1952
   352
}
ds@1952
   353
ds@1952
   354
stock bool:operator<(Float:oper1, oper2)
ds@1952
   355
{
ds@1952
   356
	return FloatCompare(oper1, float(oper2)) < 0;
ds@1952
   357
}
ds@1952
   358
ds@1952
   359
stock bool:operator<(oper1, Float:oper2)
ds@1952
   360
{
ds@1952
   361
	return FloatCompare(float(oper1), oper2) < 0;
ds@1952
   362
}
ds@1952
   363
ds@1952
   364
stock bool:operator<=(Float:oper1, Float:oper2)
ds@1952
   365
{
ds@1952
   366
	return FloatCompare(oper1, oper2) <= 0;
ds@1952
   367
}
ds@1952
   368
ds@1952
   369
stock bool:operator<=(Float:oper1, oper2)
ds@1952
   370
{
ds@1952
   371
	return FloatCompare(oper1, float(oper2)) <= 0;
ds@1952
   372
}
ds@1952
   373
ds@1952
   374
stock bool:operator<=(oper1, Float:oper2)
ds@1952
   375
{
ds@1952
   376
	return FloatCompare(float(oper1), oper2) <= 0;
ds@1952
   377
}
ds@1952
   378
ds@1952
   379
stock bool:operator!(Float:oper)
ds@1952
   380
{
ds@1952
   381
	return (_:oper & ((-1)/2)) == 0;		/* -1 = all bits to 1; /2 = remove most significant bit (sign)
ds@1952
   382
											works on both 32bit and 64bit systems; no constant required */
ds@1952
   383
}
ds@1952
   384
ds@1952
   385
/**
ds@1952
   386
 * Forbidden operators.
ds@1952
   387
 *
ds@1952
   388
 */
ds@1952
   389
forward operator%(Float:oper1, Float:oper2);
ds@1952
   390
forward operator%(Float:oper1, oper2);
ds@1952
   391
forward operator%(oper1, Float:oper2);
ds@1952
   392
ds@1952
   393
#define FLOAT_PI 3.1415926535897932384626433832795
ds@1952
   394
ds@1952
   395
/**
ds@1952
   396
 * Converts degrees to radians.
ds@1952
   397
 *
ds@1952
   398
 * @param angle		Degrees.
ds@1952
   399
 * @return			Radians.
ds@1952
   400
 */
ds@1952
   401
stock Float:DegToRad(Float:angle)
ds@1952
   402
{
ds@1952
   403
	return (angle*FLOAT_PI)/180;
ds@1952
   404
}
ds@1952
   405
ds@1952
   406
/**
ds@1952
   407
 * Converts degrees to radians.
ds@1952
   408
 *
ds@1952
   409
 * @param angle		Radians.
ds@1952
   410
 * @return			Degrees.
ds@1952
   411
 */
ds@1952
   412
stock Float:RadToDeg(Float:angle)
ds@1952
   413
{
ds@1952
   414
	return (angle*180)/FLOAT_PI;
ds@1952
   415
}