35#define BC_ARENA_SETUP \
36 char bc_arena[BC_ARENA_SIZE]; \
37 BCG(arena) = bc_arena;
39#define BC_ARENA_TEARDOWN \
41 BCG(arena_offset) = 0;
67#ifdef COMPILE_DL_BCMATH
99#if defined(COMPILE_DL_BCMATH) && defined(ZTS)
102 bcmath_globals->bc_precision = 0;
103 bcmath_globals->arena =
NULL;
104 bcmath_globals->arena_offset = 0;
115 bcmath_globals->arena =
NULL;
116 bcmath_globals->arena_offset = 0;
120static void bcmath_number_register_class(
void);
126 bcmath_number_register_class();
178 return php_str2num_ex(num, str,
NULL);
187 bool scale_param_is_null = 1;
198 if (scale_param_is_null) {
200 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
203 scale = (int) scale_param;
236 bool scale_param_is_null = 1;
247 if (scale_param_is_null) {
249 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
252 scale = (int) scale_param;
285 bool scale_param_is_null = 1;
296 if (scale_param_is_null) {
298 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
301 scale = (int) scale_param;
334 bool scale_param_is_null = 1;
345 if (scale_param_is_null) {
347 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
350 scale = (int) scale_param;
388 bool scale_param_is_null = 1;
399 if (scale_param_is_null) {
401 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
404 scale = (int) scale_param;
441 bool scale_param_is_null = 1;
452 if (scale_param_is_null) {
454 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
457 scale = (int) scale_param;
472 if (!
bc_divmod(first, second, ", &rem, scale)) {
495 zend_string *base_str, *exponent_str, *modulus_str;
497 bool scale_param_is_null = 1;
509 if (scale_param_is_null) {
511 }
else if (bcmath_check_scale(scale_param, 4) ==
FAILURE) {
514 scale = (int) scale_param;
521 if (php_str2num(&bc_base, base_str) ==
FAILURE) {
526 if (php_str2num(&bc_expo, exponent_str) ==
FAILURE) {
531 if (php_str2num(&bc_modulus, modulus_str) ==
FAILURE) {
574 bool scale_param_is_null = 1;
585 if (scale_param_is_null) {
587 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
590 scale = (int) scale_param;
597 if (php_str2num(&first, base_str) ==
FAILURE) {
602 if (php_str2num(&bc_exponent, exponent_str) ==
FAILURE) {
608 if (bc_exponent->n_scale != 0) {
613 if (exponent == 0 && (bc_exponent->n_len > 1 || bc_exponent->n_value[0] != 0)) {
639 bool scale_param_is_null = 1;
649 if (scale_param_is_null) {
651 }
else if (bcmath_check_scale(scale_param, 2) ==
FAILURE) {
654 scale = (int) scale_param;
682 bool scale_param_is_null = 1;
693 if (scale_param_is_null) {
695 }
else if (bcmath_check_scale(scale_param, 3) ==
FAILURE) {
698 scale = (int) scale_param;
735 if (php_str2num(&num, numstr) ==
FAILURE) {
781 if (mode_object !=
NULL) {
805 if (php_str2num(&num, numstr) ==
FAILURE) {
825 bool new_scale_is_null = 1;
834 if (!new_scale_is_null) {
835 if (bcmath_check_scale(new_scale, 1) ==
FAILURE) {
842 zend_string_release(new_scale_str);
843 zend_string_release(ini_name);
858#if SIZEOF_SIZE_T >= 8
859# define CHECK_RET_SCALE_OVERFLOW(scale, origin_scale) (scale > INT_MAX)
861# define CHECK_RET_SCALE_OVERFLOW(scale, origin_scale) (scale > INT_MAX || scale < origin_scale)
863#define CHECK_SCALE_OVERFLOW(scale) (scale > INT_MAX)
872 return get_bcmath_number_from_obj(
Z_OBJ_P(
zv));
880 return intern->
value;
903 zend_string_release(intern->
value);
912 bcmath_number_obj_t *clone = get_bcmath_number_from_obj(bcmath_number_create(bcmath_number_ce));
914 clone->
num = bc_copy_num(original->
num);
915 if (original->
value) {
916 clone->
value = zend_string_copy(original->
value);
941 return &
EG(error_zval);
984 return intern->
scale != 0;
1001static void bcmath_number_register_class(
void)
1009 bcmath_number_obj_handlers.
free_obj = bcmath_number_free;
1010 bcmath_number_obj_handlers.
clone_obj = bcmath_number_clone;
1011 bcmath_number_obj_handlers.
do_operation = bcmath_number_do_operation;
1012 bcmath_number_obj_handlers.
compare = bcmath_number_compare;
1013 bcmath_number_obj_handlers.
write_property = bcmath_number_write_property;
1014 bcmath_number_obj_handlers.
unset_property = bcmath_number_unset_property;
1015 bcmath_number_obj_handlers.
has_property = bcmath_number_has_property;
1016 bcmath_number_obj_handlers.
read_property = bcmath_number_read_property;
1018 bcmath_number_obj_handlers.
cast_object = bcmath_number_cast_object;
1023 size_t n1_full_scale,
size_t n2_full_scale,
size_t *scale,
bool auto_scale
1026 *scale =
MAX(n1_full_scale, n2_full_scale);
1029 (*ret)->n_scale =
MIN(*scale, (*ret)->n_scale);
1035 size_t n1_full_scale,
size_t n2_full_scale,
size_t *scale,
bool auto_scale
1038 *scale =
MAX(n1_full_scale, n2_full_scale);
1041 (*ret)->n_scale =
MIN(*scale, (*ret)->n_scale);
1047 size_t n1_full_scale,
size_t n2_full_scale,
size_t *scale,
bool auto_scale
1050 *scale = n1_full_scale + n2_full_scale;
1051 if (
UNEXPECTED(CHECK_RET_SCALE_OVERFLOW(*scale, n1_full_scale))) {
1057 (*ret)->n_scale =
MIN(*scale, (*ret)->n_scale);
1064 size_t n1_full_scale,
size_t *scale,
bool auto_scale
1068 if (
UNEXPECTED(CHECK_RET_SCALE_OVERFLOW(*scale, n1_full_scale))) {
1079 size_t diff = *scale - (*ret)->n_scale;
1087 size_t n1_full_scale,
size_t n2_full_scale,
size_t *scale,
bool auto_scale
1090 *scale =
MAX(n1_full_scale, n2_full_scale);
1102 size_t n1_full_scale,
size_t *scale,
bool auto_scale,
bool is_op
1115 bool scale_expand =
false;
1118 *scale = n1_full_scale * exponent;
1123 }
else if (exponent < 0) {
1125 if (
UNEXPECTED(CHECK_RET_SCALE_OVERFLOW(*scale, n1_full_scale))) {
1129 scale_expand =
true;
1153 size_t diff = *scale - (*ret)->n_scale;
1161 bcmath_number_obj_t *intern = get_bcmath_number_from_obj(bcmath_number_create(bcmath_number_ce));
1163 intern->
scale = scale;
1199 *full_scale = intern->
scale;
1203 return php_str2num_ex(num, str, full_scale);
1205 php_long2num(num, lval);
1235 if (
UNEXPECTED(bcmath_number_parse_num(
op1, &obj1, &str1, &lval1) ==
FAILURE || bcmath_number_parse_num(
op2, &obj2, &str2, &lval2) ==
FAILURE)) {
1241 size_t n1_full_scale;
1242 size_t n2_full_scale;
1243 if (
UNEXPECTED(bc_num_from_obj_or_str_or_long(&n1, &n1_full_scale, obj1, str1, lval1) ==
FAILURE)) {
1244 zend_value_error(
"Left string operand cannot be converted to BcMath\\Number");
1247 if (
UNEXPECTED(bc_num_from_obj_or_str_or_long(&n2, &n2_full_scale, obj2, str2, lval2) ==
FAILURE)) {
1248 zend_value_error(
"Right string operand cannot be converted to BcMath\\Number");
1252 if (
UNEXPECTED(CHECK_SCALE_OVERFLOW(n1_full_scale) || CHECK_SCALE_OVERFLOW(n2_full_scale))) {
1261 bcmath_number_add_internal(n1, n2, &
ret, n1_full_scale, n2_full_scale, &scale,
true);
1264 bcmath_number_sub_internal(n1, n2, &
ret, n1_full_scale, n2_full_scale, &scale,
true);
1267 if (
UNEXPECTED(bcmath_number_mul_internal(n1, n2, &
ret, n1_full_scale, n2_full_scale, &scale,
true) ==
FAILURE)) {
1272 if (
UNEXPECTED(bcmath_number_div_internal(n1, n2, &
ret, n1_full_scale, &scale,
true) ==
FAILURE)) {
1277 if (
UNEXPECTED(bcmath_number_mod_internal(n1, n2, &
ret, n1_full_scale, n2_full_scale, &scale,
true) ==
FAILURE)) {
1282 if (
UNEXPECTED(bcmath_number_pow_internal(n1, n2, &
ret, n1_full_scale, &scale,
true,
true) ==
FAILURE)) {
1299 if (ret_val ==
op1) {
1339 size_t n1_full_scale;
1340 size_t n2_full_scale;
1341 if (
UNEXPECTED(bc_num_from_obj_or_str_or_long(&n1, &n1_full_scale, obj1, str1, lval1) ==
FAILURE ||
1342 bc_num_from_obj_or_str_or_long(&n2, &n2_full_scale, obj2, str2, lval2) ==
FAILURE)) {
1346 if (
UNEXPECTED(CHECK_SCALE_OVERFLOW(n1_full_scale) || CHECK_SCALE_OVERFLOW(n2_full_scale))) {
1364#define BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(dest_obj, ce, dest_str, dest_long) \
1365 Z_PARAM_PROLOGUE(0, 0); \
1366 if (UNEXPECTED(!(zend_parse_arg_obj(_arg, &(dest_obj), ce, 0) || \
1367 zend_parse_arg_str_or_long(_arg, &(dest_str), &(dest_long), &_dummy, 0, _i)))) { \
1368 zend_argument_type_error(_i, "must be of type int, string, or %s, %s given", \
1369 ZSTR_VAL(bcmath_number_ce->name), zend_zval_value_name(_arg)); \
1370 _error_code = ZPP_ERROR_FAILURE; \
1377 size_t full_scale = 0;
1378 if (
UNEXPECTED(bc_num_from_obj_or_str_or_long(num, &full_scale, obj, str, lval) ==
FAILURE)) {
1382 if (
UNEXPECTED(CHECK_SCALE_OVERFLOW(full_scale))) {
1386 if (scale !=
NULL) {
1387 *scale = full_scale;
1409 if (bc_num_from_obj_or_str_or_long_with_err(&num, &scale,
NULL, str, lval, 1) ==
FAILURE) {
1415 intern->
scale = scale;
1424 bool scale_is_null =
true;
1427 BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(num_obj, bcmath_number_ce, num_str, num_lval);
1433 size_t num_full_scale = 0;
1434 if (bc_num_from_obj_or_str_or_long_with_err(&num, &num_full_scale, num_obj, num_str, num_lval, 1) ==
FAILURE) {
1437 if (bcmath_check_scale(scale_lval, 2) ==
FAILURE) {
1442 size_t scale = scale_lval;
1447 bcmath_number_add_internal(intern->
num, num, &
ret, intern->
scale, num_full_scale, &scale, scale_is_null);
1450 bcmath_number_sub_internal(intern->
num, num, &
ret, intern->
scale, num_full_scale, &scale, scale_is_null);
1475 if (num_obj ==
NULL) {
1483 if (num_obj ==
NULL) {
1525 bool scale_is_null =
true;
1528 BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(num_obj, bcmath_number_ce, num_str, num_lval);
1534 size_t num_full_scale;
1535 if (bc_num_from_obj_or_str_or_long_with_err(&num, &num_full_scale, num_obj, num_str, num_lval, 1) ==
FAILURE) {
1538 if (bcmath_check_scale(scale_lval, 2) ==
FAILURE) {
1544 size_t scale = scale_lval;
1547 if (scale_is_null) {
1548 scale =
MAX(intern->
scale, num_full_scale);
1551 if (!
bc_divmod(intern->
num, num, ", &rem, scale)) {
1558 if (num_obj ==
NULL) {
1572 if (num_obj ==
NULL) {
1589 bool scale_is_null =
true;
1592 BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(exponent_obj, bcmath_number_ce, exponent_str, exponent_lval);
1593 BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(modulus_obj, bcmath_number_ce, modulus_str, modulus_lval);
1600 if (bc_num_from_obj_or_str_or_long_with_err(&exponent_num,
NULL, exponent_obj, exponent_str, exponent_lval, 1) ==
FAILURE) {
1603 if (bc_num_from_obj_or_str_or_long_with_err(&modulus_num,
NULL, modulus_obj, modulus_str, modulus_lval, 2) ==
FAILURE) {
1606 if (bcmath_check_scale(scale_lval, 3) ==
FAILURE) {
1612 size_t scale = scale_lval;
1637 if (exponent_obj ==
NULL) {
1640 if (modulus_obj ==
NULL) {
1648 if (exponent_obj ==
NULL) {
1651 if (modulus_obj ==
NULL) {
1660 bool scale_is_null =
true;
1667 if (bcmath_check_scale(scale_lval, 1) ==
FAILURE) {
1674 if (scale_is_null) {
1691 ret->n_scale =
MIN(scale,
ret->n_scale);
1693 if (scale_is_null) {
1694 size_t diff = scale -
ret->n_scale;
1708 bool scale_is_null =
true;
1711 BCMATH_PARAM_NUMBER_OR_STR_OR_LONG(num_obj, bcmath_number_ce, num_str, num_lval);
1717 size_t num_full_scale = 0;
1718 if (bc_num_from_obj_or_str_or_long_with_err(&num, &num_full_scale, num_obj, num_str, num_lval, 1) ==
FAILURE) {
1721 if (bcmath_check_scale(scale_lval, 2) ==
FAILURE) {
1727 if (scale_is_null) {
1734 if (num_obj ==
NULL) {
1740 if (num_obj ==
NULL) {
1780 if (mode_object !=
NULL) {
1784 switch (rounding_mode) {
1850 if (php_str2num_ex(&num,
Z_STR_P(
zv), &scale) ==
FAILURE || CHECK_SCALE_OVERFLOW(scale)) {
1856 intern->
scale = scale;
bc_num bc_add(bc_num n1, bc_num n2, size_t scale_min)
pow(mixed $num, mixed $exponent)
bool bc_str2num(bc_num *num, const char *str, const char *end, size_t scale, size_t *full_scale, bool auto_scale)
bool bc_modulo(bc_num num1, bc_num num2, bc_num *resul, size_t scale)
void bc_rm_trailing_zeros(bc_num num)
void bc_init_num(bc_num *num)
bool bc_sqrt(bc_num *num, size_t scale)
long bc_num2long(bc_num num)
bc_num bc_multiply(bc_num n1, bc_num n2, size_t scale)
bc_num bc_long2num(zend_long lval)
bool bc_divmod(bc_num num1, bc_num num2, bc_num *quo, bc_num *rem, size_t scale)
bool bc_is_zero(bc_num num)
bool bc_divide(bc_num n1, bc_num n2, bc_num *quot, size_t scale)
struct bc_struct * bc_num
bc_num bc_floor_or_ceil(bc_num num, bool is_floor)
void bc_force_free_number(bc_num *num)
bc_num bc_sub(bc_num n1, bc_num n2, size_t scale_min)
void bc_round(bc_num num, zend_long places, zend_long mode, bc_num *result)
void bc_init_numbers(void)
raise_mod_status bc_raisemod(bc_num base, bc_num exponent, bc_num mod, bc_num *result, size_t scale)
bool bc_raise(bc_num base, long exponent, bc_num *result, size_t scale)
bcmath_compare_result bc_compare(bc_num n1, bc_num n2, size_t scale)
zend_string * bc_num2str_ex(bc_num num, size_t scale)
bccomp(string $num1, string $num2, ?int $scale=null)
bcpowmod(string $num, string $exponent, string $modulus, ?int $scale=null)
bcsub(string $num1, string $num2, ?int $scale=null)
bcadd(string $num1, string $num2, ?int $scale=null)
bcdivmod(string $num1, string $num2, ?int $scale=null)
bcpow(string $num, string $exponent, ?int $scale=null)
bcround(string $num, int $precision=0, RoundingMode $mode=RoundingMode::HalfAwayFromZero)
bcsqrt(string $num, ?int $scale=null)
bcmod(string $num1, string $num2, ?int $scale=null)
bcdiv(string $num1, string $num2, ?int $scale=null)
bcmul(string $num1, string $num2, ?int $scale=null)
bcscale(?int $scale=null)
#define round(tables, k1, k2)
foreach($dp as $el) foreach( $dp as $el) if( $pass2< 2) echo ""
PHPAPI int php_math_round_mode_from_enum(zend_object *mode)
php_info_print_table_start()
php_info_print_table_row(2, "PDO Driver for Firebird", "enabled")
php_info_print_table_end()
#define PHP_MSHUTDOWN_FUNCTION
#define PHP_MINIT_FUNCTION
#define PHP_MINFO_FUNCTION
#define PHP_GINIT_FUNCTION
#define PHP_GSHUTDOWN_FUNCTION
#define PHP_MODULE_GLOBALS
zend_module_entry bcmath_module_entry
struct _bcmath_number_obj_t bcmath_number_obj_t
#define BC_MATH_NUMBER_EXPAND_SCALE
#define PHP_BCMATH_VERSION
#define PHP_INI_STAGE_RUNTIME
#define STD_PHP_INI_ENTRY
#define PHP_ROUND_TOWARD_ZERO
#define PHP_ROUND_HALF_UP
#define PHP_ROUND_HALF_DOWN
#define PHP_ROUND_HALF_EVEN
#define PHP_ROUND_AWAY_FROM_ZERO
#define PHP_ROUND_HALF_ODD
#define PHP_ROUND_CEILING
zend_object *(* create_object)(zend_class_entry *class_type)
const zend_object_handlers * default_object_handlers
zend_object_write_property_t write_property
zend_object_compare_t compare
zend_object_unset_property_t unset_property
zend_object_free_obj_t free_obj
zend_object_do_operation_t do_operation
zend_object_read_property_t read_property
zend_object_cast_t cast_object
zend_object_has_property_t has_property
zend_object_get_properties_for_t get_properties_for
zend_object_clone_obj_t clone_obj
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format,...)
ZEND_API ZEND_COLD void zend_value_error(const char *format,...)
#define ZEND_TSRMLS_CACHE_UPDATE()
#define INTERNAL_FUNCTION_PARAMETERS
#define ZEND_TSRMLS_CACHE_DEFINE()
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API bool ZEND_FASTCALL zend_parse_arg_long_slow(const zval *arg, zend_long *dest, uint32_t arg_num)
ZEND_API void object_properties_init(zend_object *object, zend_class_entry *class_type)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
#define ZEND_PARSE_PARAMETERS_END()
#define ZEND_PARSE_PARAMETERS_NONE()
#define ZEND_DECLARE_MODULE_GLOBALS(module_name)
#define RETVAL_NEW_STR(s)
#define ZEND_GET_MODULE(name)
#define Z_PARAM_STR(dest)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_ARRAY_HT(dest)
#define Z_PARAM_OBJ_OF_CLASS(dest, _ce)
#define Z_PARAM_LONG_OR_NULL(dest, is_null)
#define Z_PARAM_STR_OR_LONG(dest_str, dest_long)
#define RETURN_STR_COPY(s)
ZEND_API zend_class_entry * zend_ce_division_by_zero_error
ZEND_API ZEND_COLD zend_object * zend_throw_exception_ex(zend_class_entry *exception_ce, zend_long code, const char *format,...)
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_readonly_property_modification_error_ex(const char *class_name, const char *prop_name)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_update(HashTable *ht, const char *str, size_t len, zval *pData)
ZEND_API HashTable *ZEND_FASTCALL zend_new_pair(zval *val1, zval *val2)
ZEND_API HashTable *ZEND_FASTCALL zend_array_dup(HashTable *source)
ZEND_API zval *ZEND_FASTCALL zend_hash_update(HashTable *ht, zend_string *key, zval *pData)
ZEND_API zval *ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key)
ZEND_API zend_long zend_ini_parse_quantity_warn(zend_string *value, zend_string *setting)
ZEND_API zend_result zend_alter_ini_entry(zend_string *name, zend_string *new_value, int modify_type, int stage)
#define UNREGISTER_INI_ENTRIES()
#define REGISTER_INI_ENTRIES()
#define DISPLAY_INI_ENTRIES()
#define ZEND_INI_MH(name)
#define ZEND_INI_GET_ADDR()
ZEND_API zend_class_entry * zend_ce_stringable
struct _zend_string zend_string
#define STANDARD_MODULE_HEADER
struct _zend_module_entry zend_module_entry
#define STANDARD_MODULE_PROPERTIES_EX
ZEND_API zend_result zend_std_cast_object_tostring(zend_object *readobj, zval *writeobj, int type)
ZEND_API HashTable * zend_std_get_properties(zend_object *zobj)
ZEND_API const zend_object_handlers std_object_handlers
ZEND_API zval * zend_std_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot)
ZEND_API void zend_std_unset_property(zend_object *zobj, zend_string *name, void **cache_slot)
ZEND_API zval * zend_std_read_property(zend_object *zobj, zend_string *name, int type, void **cache_slot, zval *rv)
enum _zend_prop_purpose zend_prop_purpose
#define ZEND_PROPERTY_NOT_EMPTY
ZEND_API void ZEND_FASTCALL zend_object_std_init(zend_object *object, zend_class_entry *ce)
ZEND_API void zend_object_std_dtor(zend_object *object)
ZEND_API zend_string *ZEND_FASTCALL zend_long_to_str(zend_long num)
#define ZEND_UNCOMPARABLE
#define zend_always_inline
#define XtOffsetOf(s_type, field)
#define EMPTY_SWITCH_DEFAULT_CASE()
#define UNEXPECTED(condition)
struct _zend_class_entry zend_class_entry
struct _zend_object zend_object
#define ZSTR_INIT_LITERAL(s, persistent)
#define zend_string_equals_literal(str, literal)
#define Z_ARRVAL_P(zval_p)
#define ZVAL_STR_COPY(z, s)
struct _zend_array HashTable
#define Z_STRLEN_P(zval_p)
#define Z_OBJCE_P(zval_p)
ZEND_RESULT_CODE zend_result
struct _zend_object_handlers zend_object_handlers
ZEND_API void zval_ptr_dtor(zval *zval_ptr)