summaryrefslogtreecommitdiff
path: root/ext/standard/math.c
diff options
context:
space:
mode:
authorAndrey Hristov <andrey@php.net>2005-05-13 10:11:19 +0000
committerAndrey Hristov <andrey@php.net>2005-05-13 10:11:19 +0000
commit0e459321bf5e0166c82f20d70a5886f7c81aa099 (patch)
tree60a4235bde42371ef7ed0c941f056867e942b2fc /ext/standard/math.c
parent66a821a7633b3ab87c287be0f5c6994f03eb30e5 (diff)
downloadphp-git-0e459321bf5e0166c82f20d70a5886f7c81aa099.tar.gz
move math_standard_deviation and math_variance to the stats PECL extension
Diffstat (limited to 'ext/standard/math.c')
-rw-r--r--ext/standard/math.c76
1 files changed, 0 insertions, 76 deletions
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: