]> granicus.if.org Git - php/commitdiff
fixed div by zero
authorAndrey Hristov <andrey@php.net>
Mon, 2 May 2005 12:32:21 +0000 (12:32 +0000)
committerAndrey Hristov <andrey@php.net>
Mon, 2 May 2005 12:32:21 +0000 (12:32 +0000)
#div by zero is bad...div by zero is bad...bad

ext/standard/math.c

index 3aa845fd67eda3c68d94eba3efb8b7c2052f32d3..9e2fd1273b69fdb713c7a3a4c09c7a64e245c96d 100644 (file)
@@ -1228,6 +1228,10 @@ PHP_FUNCTION(math_variance)
                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));
 }
 /* }}} */
@@ -1247,6 +1251,10 @@ PHP_FUNCTION(math_std_dev)
                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)));
 }
 /* }}} */