summaryrefslogtreecommitdiff
path: root/sql/item_sum.h
diff options
context:
space:
mode:
authortsmith@siva.hindu.god <>2007-01-18 08:30:35 -0700
committertsmith@siva.hindu.god <>2007-01-18 08:30:35 -0700
commitcc7afe24947a687df41f757c2014ac6e90897710 (patch)
tree43ed4a13aa6f4077a05dacedc68e38e0ace6b8be /sql/item_sum.h
parent230b1919512f6e5dcc15ecd765dc4f1d914acc50 (diff)
parentf2d4988c37afa398cd73b087bc3274f175c4f5b3 (diff)
downloadmariadb-git-cc7afe24947a687df41f757c2014ac6e90897710.tar.gz
Merge siva.hindu.god:/home/tsmith/m/bk/mrg-jan17/51
into siva.hindu.god:/home/tsmith/m/bk/mrg-jan17/maint/51
Diffstat (limited to 'sql/item_sum.h')
-rw-r--r--sql/item_sum.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/sql/item_sum.h b/sql/item_sum.h
index fdc13a36874..4cf16fc79af 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -682,8 +682,10 @@ public:
double val_real();
longlong val_int()
{ /* can't be fix_fields()ed */ return (longlong) rint(val_real()); }
- String *val_str(String*);
- my_decimal *val_decimal(my_decimal *);
+ String *val_str(String *str)
+ { return val_string_from_real(str); }
+ my_decimal *val_decimal(my_decimal *dec_buf)
+ { return val_decimal_from_real(dec_buf); }
bool is_null() { update_null_value(); return null_value; }
enum_field_types field_type() const
{
@@ -705,6 +707,14 @@ public:
= (sum(ai^2) - 2*sum(a)*sum(a)/count(a) + count(a)*sum(a)^2/count(a)^2 )/count(a) =
= (sum(ai^2) - 2*sum(a)^2/count(a) + sum(a)^2/count(a) )/count(a) =
= (sum(ai^2) - sum(a)^2/count(a))/count(a)
+
+But, this falls prey to catastrophic cancellation. Instead, use the recurrence formulas
+
+ M_{1} = x_{1}, ~ M_{k} = M_{k-1} + (x_{k} - M_{k-1}) / k newline
+ S_{1} = 0, ~ S_{k} = S_{k-1} + (x_{k} - M_{k-1}) times (x_{k} - M_{k}) newline
+ for 2 <= k <= n newline
+ ital variance = S_{n} / (n-1)
+
*/
class Item_sum_variance : public Item_sum_num
@@ -713,9 +723,8 @@ class Item_sum_variance : public Item_sum_num
public:
Item_result hybrid_type;
- double sum, sum_sqr;
- my_decimal dec_sum[2], dec_sqr[2];
int cur_dec;
+ double recurrence_m, recurrence_s; /* Used in recurrence relation. */
ulonglong count;
uint f_precision0, f_scale0;
uint f_precision1, f_scale1;
@@ -724,7 +733,7 @@ public:
uint prec_increment;
Item_sum_variance(Item *item_par, uint sample_arg) :Item_sum_num(item_par),
- hybrid_type(REAL_RESULT), cur_dec(0), count(0), sample(sample_arg)
+ hybrid_type(REAL_RESULT), count(0), sample(sample_arg)
{}
Item_sum_variance(THD *thd, Item_sum_variance *item);
enum Sumfunctype sum_func () const { return VARIANCE_FUNC; }
@@ -744,7 +753,6 @@ public:
enum Item_result result_type () const { return REAL_RESULT; }
void cleanup()
{
- cur_dec= 0;
count= 0;
Item_sum_num::cleanup();
}