Skip to content

Add BCMath PHP stubs #4508

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 5 additions & 65 deletions ext/bcmath/bcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#if HAVE_BCMATH

#include "php_ini.h"
#include "bcmath_arginfo.h"
#include "ext/standard/info.h"
#include "php_bcmath.h"
#include "libbcmath/src/bcmath.h"
Expand All @@ -33,67 +34,6 @@ ZEND_DECLARE_MODULE_GLOBALS(bcmath)
static PHP_GINIT_FUNCTION(bcmath);
static PHP_GSHUTDOWN_FUNCTION(bcmath);

/* {{{ arginfo */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcadd, 0, 2, IS_STRING, 0)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsub, 0, 2, IS_STRING, 0)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcmul, 0, 2, IS_STRING, 0)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcdiv, 0, 2, IS_STRING, 1)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcmod, 0, 2, IS_STRING, 1)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_bcpowmod, 0, 0, 3)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_ARG_INFO(0, mod)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcpow, 0, 2, IS_STRING, 0)
ZEND_ARG_INFO(0, x)
ZEND_ARG_INFO(0, y)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsqrt, 0, 1, IS_STRING, 1)
ZEND_ARG_INFO(0, operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bccomp, 0, 2, IS_LONG, 0)
ZEND_ARG_INFO(0, left_operand)
ZEND_ARG_INFO(0, right_operand)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcscale, 0, 0, IS_LONG, 0)
ZEND_ARG_INFO(0, scale)
ZEND_END_ARG_INFO()

/* }}} */

static const zend_function_entry bcmath_functions[] = {
PHP_FE(bcadd, arginfo_bcadd)
PHP_FE(bcsub, arginfo_bcsub)
Expand Down Expand Up @@ -400,18 +340,18 @@ PHP_FUNCTION(bcmod)
/* }}} */

/* {{{ proto string bcpowmod(string x, string y, string mod [, int scale])
Returns the value of an arbitrary precision number raised to the power of another reduced by a modulous */
Returns the value of an arbitrary precision number raised to the power of another reduced by a modulus */
PHP_FUNCTION(bcpowmod)
{
zend_string *left, *right, *modulous;
zend_string *left, *right, *modulus;
bc_num first, second, mod, result;
zend_long scale = BCG(bc_precision);
int scale_int;

ZEND_PARSE_PARAMETERS_START(3, 4)
Z_PARAM_STR(left)
Z_PARAM_STR(right)
Z_PARAM_STR(modulous)
Z_PARAM_STR(modulus)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(scale)
ZEND_PARSE_PARAMETERS_END();
Expand All @@ -422,7 +362,7 @@ PHP_FUNCTION(bcpowmod)
bc_init_num(&result);
php_str2num(&first, ZSTR_VAL(left));
php_str2num(&second, ZSTR_VAL(right));
php_str2num(&mod, ZSTR_VAL(modulous));
php_str2num(&mod, ZSTR_VAL(modulus));

scale_int = (int) ((int)scale < 0 ? 0 : scale);

Expand Down
22 changes: 22 additions & 0 deletions ext/bcmath/bcmath.stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

function bcadd(string $left_operand, string $right_operand, int $scale = UNKNOWN) : string {}

function bcsub(string $left_operand, string $right_operand, int $scale = UNKNOWN) : string {}

function bcmul(string $left_operand, string $right_operand, int $scale = UNKNOWN) : string {}

function bcdiv(string $dividend, string $divisor, int $scale = UNKNOWN) : ?string {}

function bcmod(string $dividend, string $divisor, int $scale = UNKNOWN) : ?string {}

/** @return string|false */
function bcpowmod(string $base, string $exponent, string $modulus, int $scale = UNKNOWN) {}

function bcpow(string $base, string $exponent, int $scale = UNKNOWN) : string {}

function bcsqrt(string $operand, int $scale = UNKNOWN) : ?string {}

function bccomp(string $left_operand, string $right_operand, int $scale = UNKNOWN) : int {}

function bcscale(int $scale = UNKNOWN) : int {}
47 changes: 47 additions & 0 deletions ext/bcmath/bcmath_arginfo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcadd, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, left_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, right_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_bcsub arginfo_bcadd

#define arginfo_bcmul arginfo_bcadd

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcdiv, 0, 2, IS_STRING, 1)
ZEND_ARG_TYPE_INFO(0, dividend, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, divisor, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_bcmod arginfo_bcdiv

ZEND_BEGIN_ARG_INFO_EX(arginfo_bcpowmod, 0, 0, 3)
ZEND_ARG_TYPE_INFO(0, base, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, exponent, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, modulus, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcpow, 0, 2, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, base, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, exponent, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcsqrt, 0, 1, IS_STRING, 1)
ZEND_ARG_TYPE_INFO(0, operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bccomp, 0, 2, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, left_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, right_operand, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_bcscale, 0, 0, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, scale, IS_LONG, 0)
ZEND_END_ARG_INFO()