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