Convert math module to static Math class

This commit is contained in:
2026-11-23 10:22:11 +01:00
parent c981572bae
commit 2243557bf5
6 changed files with 865 additions and 861 deletions
-53
View File
@@ -202,58 +202,6 @@ static int PH7_builtin_is_resource(ph7_context *pCtx, int nArg, ph7_value **apAr
ph7_result_bool(pCtx, res);
return PH7_OK;
}
/*
* float round ( float $val [, int $precision = 0 [, int $mode = PHP_ROUND_HALF_UP ]] )
* Exponential expression.
* Parameter
* $val
* The value to round.
* $precision
* The optional number of decimal digits to round to.
* $mode
* One of PHP_ROUND_HALF_UP, PHP_ROUND_HALF_DOWN, PHP_ROUND_HALF_EVEN, or PHP_ROUND_HALF_ODD.
* (not supported).
* Return
* The rounded value.
*/
static int PH7_builtin_round(ph7_context *pCtx, int nArg, ph7_value **apArg) {
int n = 0;
double r;
if(nArg < 1) {
/* Missing argument, return 0 */
ph7_result_int(pCtx, 0);
return PH7_OK;
}
/* Extract the precision if available */
if(nArg > 1) {
n = ph7_value_to_int(apArg[1]);
if(n > 30) {
n = 30;
}
if(n < 0) {
n = 0;
}
}
r = ph7_value_to_double(apArg[0]);
/* If Y==0 and X will fit in a 64-bit int,
* handle the rounding directly.Otherwise
* use our own custom printf [i.e:SyBufferFormat()].
*/
if(n == 0 && r >= 0 && r < LARGEST_INT64 - 1) {
r = (double)((ph7_int64)(r + 0.5));
} else if(n == 0 && r < 0 && (-r) < LARGEST_INT64 - 1) {
r = -(double)((ph7_int64)((-r) + 0.5));
} else {
char zBuf[256];
sxu32 nLen;
nLen = SyBufferFormat(zBuf, sizeof(zBuf), "%.*f", n, r);
/* Convert the string to real number */
SyStrToReal(zBuf, nLen, (void *)&r, 0);
}
/* Return thr rounded value */
ph7_result_double(pCtx, r);
return PH7_OK;
}
/*
* string dechex(int $number)
* Decimal to hexadecimal.
@@ -7456,7 +7404,6 @@ static const ph7_builtin_func aBuiltInFunc[] = {
{ "is_string", PH7_builtin_is_string },
{ "is_void", PH7_builtin_is_void },
{ "is_numeric", PH7_builtin_is_numeric },
{ "round", PH7_builtin_round },
{ "dechex", PH7_builtin_dechex },
{ "decoct", PH7_builtin_decoct },
{ "decbin", PH7_builtin_decbin },