F0("hypot", MAY_BE_DOUBLE),
F0("deg2rad", MAY_BE_DOUBLE),
F0("rad2deg", MAY_BE_DOUBLE),
- F0("bindec", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_DOUBLE),
- F0("hexdec", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_DOUBLE),
- F0("octdec", MAY_BE_FALSE | MAY_BE_LONG | MAY_BE_DOUBLE),
+ F0("bindec", MAY_BE_LONG | MAY_BE_DOUBLE),
+ F0("hexdec", MAY_BE_LONG | MAY_BE_DOUBLE),
+ F0("octdec", MAY_BE_LONG | MAY_BE_DOUBLE),
F1("decbin", MAY_BE_STRING),
F1("decoct", MAY_BE_STRING),
F1("dechex", MAY_BE_STRING),
/*
* Convert a string representation of a base(2-36) number to a zval.
*/
-PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret)
+PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret)
{
zend_long num = 0;
double fnum = 0;
zend_long cutoff;
int cutlim;
- if (Z_TYPE_P(arg) != IS_STRING || base < 2 || base > 36) {
- return FAILURE;
- }
-
- s = Z_STRVAL_P(arg);
+ s = ZSTR_VAL(str);
cutoff = ZEND_LONG_MAX / base;
cutlim = ZEND_LONG_MAX % base;
- for (i = Z_STRLEN_P(arg); i > 0; i--) {
+ for (i = ZSTR_LEN(str); i > 0; i--) {
c = *s++;
/* might not work for EBCDIC */
} else {
ZVAL_LONG(ret, num);
}
- return SUCCESS;
}
/* }}} */
}
/* }}} */
-/* {{{ proto int bindec(string binary_number)
+/* {{{ proto int|float bindec(string binary_number)
Returns the decimal equivalent of the binary number */
PHP_FUNCTION(bindec)
{
- zval *arg;
+ zend_string *arg;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(arg)
+ Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();
- convert_to_string_ex(arg);
- if (_php_math_basetozval(arg, 2, return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ _php_math_basetozval(arg, 2, return_value);
}
/* }}} */
-/* {{{ proto int hexdec(string hexadecimal_number)
+/* {{{ proto int|flat hexdec(string hexadecimal_number)
Returns the decimal equivalent of the hexadecimal number */
PHP_FUNCTION(hexdec)
{
- zval *arg;
+ zend_string *arg;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(arg)
+ Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();
- convert_to_string_ex(arg);
- if (_php_math_basetozval(arg, 16, return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ _php_math_basetozval(arg, 16, return_value);
}
/* }}} */
-/* {{{ proto int octdec(string octal_number)
+/* {{{ proto int|float octdec(string octal_number)
Returns the decimal equivalent of an octal string */
PHP_FUNCTION(octdec)
{
- zval *arg;
+ zend_string *arg;
ZEND_PARSE_PARAMETERS_START(1, 1)
- Z_PARAM_ZVAL(arg)
+ Z_PARAM_STR(arg)
ZEND_PARSE_PARAMETERS_END();
- convert_to_string_ex(arg);
- if (_php_math_basetozval(arg, 8, return_value) == FAILURE) {
- RETURN_FALSE;
- }
+ _php_math_basetozval(arg, 8, return_value);
}
/* }}} */
RETURN_FALSE;
}
- if(_php_math_basetozval(number, (int)frombase, &temp) == FAILURE) {
- RETURN_FALSE;
- }
+ _php_math_basetozval(Z_STR_P(number), (int)frombase, &temp);
result = _php_math_zvaltobase(&temp, (int)tobase);
RETVAL_STR(result);
}
PHPAPI zend_string *_php_math_number_format_ex(double, int, char *, size_t, char *, size_t);
PHPAPI zend_string * _php_math_longtobase(zval *arg, int base);
PHPAPI zend_long _php_math_basetolong(zval *arg, int base);
-PHPAPI int _php_math_basetozval(zval *arg, int base, zval *ret);
+PHPAPI void _php_math_basetozval(zend_string *str, int base, zval *ret);
PHPAPI zend_string * _php_math_zvaltobase(zval *arg, int base);
PHP_FUNCTION(sin);
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(bindec($input));
+ try {
+ var_dump(bindec($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing bindec() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 18 --
-
-Notice: Array to string conversion in %s on line %d
-int(0)
+bindec() expects parameter 1 to be string, array given
-- Iteration 19 --
int(0)
int(0)
-- Iteration 24 --
-int(%d)
+bindec() expects parameter 1 to be string, resource given
===Done===
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(hexdec($input));
+ try {
+ var_dump(hexdec($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
===Done===
---EXPECTF--
+--EXPECT--
*** Testing hexdec() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 20 --
-
-Notice: Array to string conversion in %s on line %d
-int(170)
+hexdec() expects parameter 1 to be string, array given
-- Iteration 21 --
int(2748)
int(0)
-- Iteration 26 --
-%s
+hexdec() expects parameter 1 to be string, resource given
===Done===
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
- var_dump(octdec($input));
+ try {
+ var_dump(octdec($input));
+ } catch (TypeError $e) {
+ echo $e->getMessage(), "\n";
+ }
$iterator++;
};
fclose($fp);
?>
---Done---
---EXPECTF--
+--EXPECT--
*** Testing octdec() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 20 --
-
-Notice: Array to string conversion in %s on line %d
-int(0)
+octdec() expects parameter 1 to be string, array given
-- Iteration 21 --
int(0)
int(0)
-- Iteration 26 --
-int(%d)
+octdec() expects parameter 1 to be string, resource given
---Done---