From: Andrey Hristov Date: Fri, 13 May 2005 10:11:19 +0000 (+0000) Subject: move math_standard_deviation and math_variance to the stats PECL extension X-Git-Tag: php-5.0.1b1~246 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e459321bf5e0166c82f20d70a5886f7c81aa099;p=php move math_standard_deviation and math_variance to the stats PECL extension --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index dd6893ff6a..41c9211369 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -415,8 +415,6 @@ function_entry basic_functions[] = { PHP_FE(base_convert, NULL) PHP_FE(number_format, NULL) PHP_FE(fmod, NULL) - PHP_FE(math_standard_deviation, NULL) - PHP_FE(math_variance, NULL) #ifdef HAVE_INET_NTOP PHP_NAMED_FE(inet_ntop, php_inet_ntop, NULL) #endif diff --git a/ext/standard/math.c b/ext/standard/math.c index 62bce33389..fdfbeb6d81 100644 --- a/ext/standard/math.c +++ b/ext/standard/math.c @@ -1137,83 +1137,7 @@ PHP_FUNCTION(fmod) } /* }}} */ -/* {{{ php_population_variance -*/ -static long double php_population_variance(zval *arr, zend_bool sample) -{ - double mean, sum = 0.0, vr = 0.0; - zval **entry; - HashPosition pos; - int elements_num; - - elements_num = zend_hash_num_elements(Z_ARRVAL_P(arr)); - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS) { - convert_to_double_ex(entry); - sum += Z_DVAL_PP(entry); - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); - } - mean = sum / elements_num; - - zend_hash_internal_pointer_reset_ex(Z_ARRVAL_P(arr), &pos); - while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **)&entry, &pos) == SUCCESS) { - double d; - convert_to_double_ex(entry); - d = Z_DVAL_PP(entry) - mean; - vr += d*d; - zend_hash_move_forward_ex(Z_ARRVAL_P(arr), &pos); - } - if (sample) { - --elements_num; - } - return (vr / elements_num); -} -/* }}} */ - -/* {{{ proto float math_variance(array a [, bool sample]) - Returns the population variance */ -PHP_FUNCTION(math_variance) -{ - zval *arr; - zend_bool sample = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &arr, &sample) == FAILURE) { - return; - } - if (zend_hash_num_elements(Z_ARRVAL_P(arr)) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array has zero elements"); - RETURN_FALSE; - } - if (sample && zend_hash_num_elements(Z_ARRVAL_P(arr)) == 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array has only 1 element"); - RETURN_FALSE; - } - RETURN_DOUBLE(php_population_variance(arr, sample)); -} -/* }}} */ - -/* {{{ proto float math_standard_deviation(array a[, bool sample = false]) - Returns the standard deviation */ -PHP_FUNCTION(math_standard_deviation) -{ - zval *arr; - zend_bool sample = 0; - - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &arr, &sample) == FAILURE) { - return; - } - if (zend_hash_num_elements(Z_ARRVAL_P(arr)) == 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array has zero elements"); - RETURN_FALSE; - } - if (sample && zend_hash_num_elements(Z_ARRVAL_P(arr)) == 1) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "The array has only 1 element"); - RETURN_FALSE; - } - RETURN_DOUBLE(sqrt(php_population_variance(arr, sample))); -} -/* }}} */ /* * Local variables: diff --git a/ext/standard/php_math.h b/ext/standard/php_math.h index 70c30a8a68..adbc9f8cdf 100644 --- a/ext/standard/php_math.h +++ b/ext/standard/php_math.h @@ -59,8 +59,6 @@ PHP_FUNCTION(octdec); PHP_FUNCTION(base_convert); PHP_FUNCTION(number_format); PHP_FUNCTION(fmod); -PHP_FUNCTION(math_standard_deviation); -PHP_FUNCTION(math_variance); PHP_FUNCTION(deg2rad); PHP_FUNCTION(rad2deg); diff --git a/ext/standard/tests/math/math_std_dev.phpt b/ext/standard/tests/math/math_std_dev.phpt deleted file mode 100644 index f7a00ff9d7..0000000000 --- a/ext/standard/tests/math/math_std_dev.phpt +++ /dev/null @@ -1,24 +0,0 @@ ---TEST-- -math_standard_deviation()/math_variance tests ---FILE-- - ---EXPECTF-- -string(11) "2.449489743" - -Warning: math_standard_deviation(): The array has zero elements in %s on line %d -bool(false) -float(2.1213203435596) ----Variance--- -float(3.6) -float(4.5) \ No newline at end of file