2008-10-04 22:59:11 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
2009-04-14 23:40:48 +02:00
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
2008-10-04 22:59:11 +02:00
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* 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>.
|
|
|
|
*
|
2009-04-14 23:40:48 +02:00
|
|
|
* Version: $Id$
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined _float_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _float_included
|
|
|
|
|
2015-03-21 15:43:24 +01:00
|
|
|
#if !defined __sourcepawn2__
|
2008-10-04 22:59:11 +02:00
|
|
|
/**
|
|
|
|
* Converts an integer into a floating point value.
|
|
|
|
*
|
|
|
|
* @param value Integer to convert.
|
|
|
|
* @return Floating point value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float float(int value);
|
2015-03-21 15:43:24 +01:00
|
|
|
#endif
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Multiplies two floats together.
|
|
|
|
*
|
|
|
|
* @param oper1 First value.
|
|
|
|
* @param oper2 Second value.
|
|
|
|
* @return oper1*oper2.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatMul(float oper1, float oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Divides the dividend by the divisor.
|
|
|
|
*
|
|
|
|
* @param dividend First value.
|
|
|
|
* @param divisor Second value.
|
|
|
|
* @return dividend/divisor.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatDiv(float dividend, float divisor);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds two floats together.
|
|
|
|
*
|
|
|
|
* @param oper1 First value.
|
|
|
|
* @param oper2 Second value.
|
|
|
|
* @return oper1+oper2.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatAdd(float oper1, float oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Subtracts oper2 from oper1.
|
|
|
|
*
|
|
|
|
* @param oper1 First value.
|
|
|
|
* @param oper2 Second value.
|
|
|
|
* @return oper1-oper2.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatSub(float oper1, float oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the decimal part of a float.
|
|
|
|
*
|
|
|
|
* @param value Input value.
|
|
|
|
* @return Decimal part.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatFraction(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounds a float to the closest integer to zero.
|
|
|
|
*
|
|
|
|
* @param value Input value to be rounded.
|
|
|
|
* @return Rounded value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int RoundToZero(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounds a float to the next highest integer value.
|
|
|
|
*
|
|
|
|
* @param value Input value to be rounded.
|
|
|
|
* @return Rounded value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int RoundToCeil(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rounds a float to the next lowest integer value.
|
|
|
|
*
|
|
|
|
* @param value Input value to be rounded.
|
|
|
|
* @return Rounded value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int RoundToFloor(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Standard IEEE rounding.
|
|
|
|
*
|
|
|
|
* @param value Input value to be rounded.
|
|
|
|
* @return Rounded value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int RoundToNearest(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int FloatCompare(float fOne, float fTwo);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the square root of the input value, equivalent to floatpower(value, 0.5).
|
|
|
|
*
|
|
|
|
* @param value Input value.
|
|
|
|
* @return Square root of the value.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float SquareRoot(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Pow(float value, float exponent);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the value of raising the input by e.
|
|
|
|
*
|
|
|
|
* @param value Input value.
|
|
|
|
* @return exp(value).
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Exponential(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Logarithm(float value, float base=10.0);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the sine of the argument.
|
|
|
|
*
|
|
|
|
* @param value Input value in radians.
|
|
|
|
* @return sin(value).
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Sine(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the cosine of the argument.
|
|
|
|
*
|
|
|
|
* @param value Input value in radians.
|
|
|
|
* @return cos(value).
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Cosine(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the tangent of the argument.
|
|
|
|
*
|
|
|
|
* @param value Input value in radians.
|
|
|
|
* @return tan(value).
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float Tangent(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an absolute value.
|
|
|
|
*
|
|
|
|
* @param value Input value.
|
|
|
|
* @return Absolute value of the input.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float FloatAbs(float value);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the arctangent of the input value.
|
|
|
|
*
|
|
|
|
* @param angle Input value.
|
|
|
|
* @return atan(value) in radians.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float ArcTangent(float angle);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the arccosine of the input value.
|
|
|
|
*
|
|
|
|
* @param angle Input value.
|
|
|
|
* @return acos(value) in radians.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float ArcCosine(float angle);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the arcsine of the input value.
|
|
|
|
*
|
|
|
|
* @param angle Input value.
|
|
|
|
* @return asin(value) in radians.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float ArcSine(float angle);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the arctangent2 of the input values.
|
|
|
|
*
|
|
|
|
* @param x Horizontal value.
|
|
|
|
* @param y Vertical value.
|
|
|
|
* @return atan2(value) in radians.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float ArcTangent2(float x, float y);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock int RoundFloat(float value)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return RoundToNearest(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* User defined operators.
|
|
|
|
*/
|
2015-03-21 15:43:24 +01:00
|
|
|
#if !defined __sourcepawn2__
|
2008-10-04 22:59:11 +02:00
|
|
|
#pragma rational Float
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
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)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return oper+1.0;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator--(float oper)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return oper-1.0;
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator-(float oper)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
return oper^view_as<float>(cellmin); /* IEEE values are sign/magnitude */
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator*(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatMul(oper1, float(oper2)); /* "*" is commutative */
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator/(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatDiv(oper1, float(oper2));
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator/(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatDiv(float(oper1), oper2);
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator+(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatAdd(oper1, float(oper2)); /* "+" is commutative */
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator-(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatSub(oper1, float(oper2));
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float operator-(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return FloatSub(float(oper1), oper2);
|
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator==(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_EQ__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator!=(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_NE__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator>(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_GT__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator>(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_GT__(float(oper1), oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator>=(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_GE__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator>=(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_GE__(float(oper1), oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator<(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_LT__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator<(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_LT__(float(oper1), oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator<=(float oper1, int oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_LE__(oper1, float(oper2));
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 15:34:00 +02:00
|
|
|
stock bool operator<=(int oper1, float oper2)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2014-07-30 11:03:42 +02:00
|
|
|
return __FLOAT_LE__(float(oper1), oper2);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Forbidden operators.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
forward operator%(float oper1, float oper2);
|
|
|
|
forward operator%(float oper1, int oper2);
|
|
|
|
forward operator%(int oper1, float oper2);
|
2015-03-21 15:43:24 +01:00
|
|
|
#endif // __sourcepawn2__
|
2008-10-04 22:59:11 +02:00
|
|
|
|
|
|
|
#define FLOAT_PI 3.1415926535897932384626433832795
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts degrees to radians.
|
|
|
|
*
|
|
|
|
* @param angle Degrees.
|
|
|
|
* @return Radians.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float DegToRad(float angle)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return (angle*FLOAT_PI)/180;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts degrees to radians.
|
|
|
|
*
|
|
|
|
* @param angle Radians.
|
|
|
|
* @return Degrees.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock float RadToDeg(float angle)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
|
|
|
return (angle*180)/FLOAT_PI;
|
|
|
|
}
|
2010-07-25 20:58:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a random integer in the range [0, 2^31-1].
|
|
|
|
*
|
|
|
|
* Note: Uniform random number streams are seeded automatically per-plugin.
|
|
|
|
*
|
|
|
|
* @return Random integer.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native int GetURandomInt();
|
2010-07-25 20:58:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native float GetURandomFloat();
|
2010-07-25 20:58:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
native void SetURandomSeed(const int[] seeds, int numSeeds);
|
2010-07-25 20:58:18 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-08-23 15:34:00 +02:00
|
|
|
stock void SetURandomSeedSimple(int seed)
|
2010-07-25 20:58:18 +02:00
|
|
|
{
|
2016-08-23 15:34:00 +02:00
|
|
|
int seeds[1];
|
2010-07-25 20:58:18 +02:00
|
|
|
seeds[0] = seed;
|
|
|
|
SetURandomSeed(seeds, 1);
|
|
|
|
}
|