Add support for float modulo operator (#1953)
This commit is contained in:
parent
a9a1939f75
commit
5539484f92
@ -231,6 +231,13 @@ static cell_t sm_FloatFraction(IPluginContext *pCtx, const cell_t *params)
|
||||
return sp_ftoc(val);
|
||||
}
|
||||
|
||||
static cell_t sm_FloatMod(IPluginContext* pCtx, const cell_t* params)
|
||||
{
|
||||
float val = fmodf(sp_ctof(params[1]), sp_ctof(params[2]));
|
||||
|
||||
return sp_ftoc(val);
|
||||
}
|
||||
|
||||
static cell_t sm_Sine(IPluginContext *pCtx, const cell_t *params)
|
||||
{
|
||||
float val = sp_ctof(params[1]);
|
||||
@ -358,6 +365,7 @@ REGISTER_NATIVES(floatnatives)
|
||||
{"FloatAdd", sm_FloatAdd},
|
||||
{"FloatSub", sm_FloatSub},
|
||||
{"FloatFraction", sm_FloatFraction},
|
||||
{"FloatMod", sm_FloatMod},
|
||||
{"RoundToZero", sm_RoundToZero},
|
||||
{"RoundToCeil", sm_RoundToCeil},
|
||||
{"RoundToFloor", sm_RoundToFloor},
|
||||
|
@ -97,6 +97,19 @@ native float FloatAdd(float oper1, float oper2);
|
||||
#pragma deprecated This native is internal implementation. For subtraction use the '-' operator.
|
||||
native float FloatSub(float oper1, float oper2);
|
||||
|
||||
/**
|
||||
* Returns the modulus of oper1 and oper2.
|
||||
*
|
||||
* Note: This native is internal implementation. For modulo use the '%' operator.
|
||||
*
|
||||
* @param oper1 First value.
|
||||
* @param oper2 Second value.
|
||||
* @return oper1%oper2.
|
||||
* @deprecated This native is internal implementation. For modulo use the '%' operator.
|
||||
*/
|
||||
#pragma deprecated This native is internal implementation. For modulo use the '%' operator.
|
||||
native float FloatMod(float oper1, float oper2);
|
||||
|
||||
/**
|
||||
* Returns the decimal part of a float.
|
||||
*
|
||||
@ -269,6 +282,7 @@ native float __FLOAT_MUL__(float a, float b) = FloatMul;
|
||||
native float __FLOAT_DIV__(float a, float b) = FloatDiv;
|
||||
native float __FLOAT_ADD__(float a, float b) = FloatAdd;
|
||||
native float __FLOAT_SUB__(float a, float b) = FloatSub;
|
||||
native float __FLOAT_MOD__(float a, float b) = FloatMod;
|
||||
|
||||
native bool __FLOAT_GT__(float a, float b);
|
||||
native bool __FLOAT_GE__(float a, float b);
|
||||
@ -282,6 +296,7 @@ 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 float operator%(float oper1, float oper2) = FloatMod;
|
||||
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__;
|
||||
@ -387,12 +402,15 @@ stock bool operator<=(int oper1, float oper2)
|
||||
return __FLOAT_LE__(float(oper1), oper2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forbidden operators.
|
||||
*/
|
||||
forward float operator%(float oper1, float oper2);
|
||||
forward float operator%(float oper1, int oper2);
|
||||
forward float operator%(int oper1, float oper2);
|
||||
stock float operator%(float oper1, int oper2)
|
||||
{
|
||||
return __FLOAT_MOD__(oper1, float(oper2));
|
||||
}
|
||||
|
||||
stock float operator%(int oper1, float oper2)
|
||||
{
|
||||
return __FLOAT_MOD__(float(oper1), oper2);
|
||||
}
|
||||
#endif // __sourcepawn2__
|
||||
|
||||
#define FLOAT_PI 3.1415926535897932384626433832795
|
||||
|
Loading…
Reference in New Issue
Block a user