From: John Darrington Date: Sat, 20 Sep 2008 01:35:58 +0000 (+0800) Subject: Used pow2(x) instead of x * x where appropriate. X-Git-Tag: v0.7.1~50^2~55 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=08590721e2938b1a7db320bfac2d4f1f86afa717;p=pspp-builds.git Used pow2(x) instead of x * x where appropriate. --- diff --git a/src/language/expressions/helpers.c b/src/language/expressions/helpers.c index 695c2335..85705098 100644 --- a/src/language/expressions/helpers.c +++ b/src/language/expressions/helpers.c @@ -589,7 +589,7 @@ ncdf_beta (double x, double a, double b, double lambda) double cdf_bvnor (double x0, double x1, double r) { - double z = x0 * x0 - 2. * r * x0 * x1 + x1 * x1; + double z = pow2 (x0) - 2. * r * x0 * x1 + pow2 (x1); return exp (-z / (2. * (1 - r * r))) * (2. * M_PI * sqrt (1 - r * r)); } diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index fcfccc39..d49e3006 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -2456,7 +2456,7 @@ calc_r (double *X, double *Y, double *r, double *ase_0, double *ase_1) for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++) { sum_Xr += X[i] * row_tot[i]; - sum_X2r += X[i] * X[i] * row_tot[i]; + sum_X2r += pow2 (X[i]) * row_tot[i]; } Xbar = sum_Xr / W; @@ -2468,11 +2468,11 @@ calc_r (double *X, double *Y, double *r, double *ase_0, double *ase_1) Ybar = sum_Yc / W; S = sum_XYf - sum_Xr * sum_Yc / W; - SX = sum_X2r - sum_Xr * sum_Xr / W; - SY = sum_Y2c - sum_Yc * sum_Yc / W; + SX = sum_X2r - pow2 (sum_Xr) / W; + SY = sum_Y2c - pow2 (sum_Yc) / W; T = sqrt (SX * SY); *r = S / T; - *ase_0 = sqrt ((sum_X2Y2f - (sum_XYf * sum_XYf) / W) / (sum_X2r * sum_Y2c)); + *ase_0 = sqrt ((sum_X2Y2f - pow2 (sum_XYf) / W) / (sum_X2r * sum_Y2c)); { double s, c, y, t; @@ -2562,9 +2562,9 @@ calc_symmetric (double v[N_SYMMETRIC], double ase[N_SYMMETRIC], Dr = Dc = W * W; for (r = 0; r < n_rows; r++) - Dr -= row_tot[r] * row_tot[r]; + Dr -= pow2 (row_tot[r]); for (c = 0; c < n_cols; c++) - Dc -= col_tot[c] * col_tot[c]; + Dc -= pow2 (col_tot[c]); } { @@ -3073,10 +3073,10 @@ calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL], } for (sum_ri2 = 0., i = 0; i < n_rows; i++) - sum_ri2 += row_tot[i] * row_tot[i]; + sum_ri2 += pow2 (row_tot[i]); for (sum_cj2 = 0., j = 0; j < n_cols; j++) - sum_cj2 += col_tot[j] * col_tot[j]; + sum_cj2 += pow2 (col_tot[j]); v[3] = (W * sum_fij2_ci - sum_ri2) / (W * W - sum_ri2); v[4] = (W * sum_fij2_ri - sum_cj2) / (W * W - sum_cj2); @@ -3166,9 +3166,9 @@ calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL], for (sum_Xr = sum_X2r = 0., i = 0; i < n_rows; i++) { sum_Xr += rows[i].f * row_tot[i]; - sum_X2r += rows[i].f * rows[i].f * row_tot[i]; + sum_X2r += pow2 (rows[i].f) * row_tot[i]; } - SX = sum_X2r - sum_Xr * sum_Xr / W; + SX = sum_X2r - pow2 (sum_Xr) / W; for (SXW = 0., j = 0; j < n_cols; j++) { @@ -3176,7 +3176,7 @@ calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL], for (cum = 0., i = 0; i < n_rows; i++) { - SXW += rows[i].f * rows[i].f * mat[j + i * n_cols]; + SXW += pow2 (rows[i].f) * mat[j + i * n_cols]; cum += rows[i].f * mat[j + i * n_cols]; } @@ -3193,7 +3193,7 @@ calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL], for (sum_Yc = sum_Y2c = 0., i = 0; i < n_cols; i++) { sum_Yc += cols[i].f * col_tot[i]; - sum_Y2c += cols[i].f * cols[i].f * col_tot[i]; + sum_Y2c += pow2 (cols[i].f) * col_tot[i]; } SY = sum_Y2c - sum_Yc * sum_Yc / W; @@ -3203,7 +3203,7 @@ calc_directional (double v[N_DIRECTIONAL], double ase[N_DIRECTIONAL], for (cum = 0., j = 0; j < n_cols; j++) { - SYW += cols[j].f * cols[j].f * mat[j + i * n_cols]; + SYW += pow2 (cols[j].f) * mat[j + i * n_cols]; cum += cols[j].f * mat[j + i * n_cols]; } diff --git a/src/language/stats/oneway.q b/src/language/stats/oneway.q index 0600fdf2..46cdd566 100644 --- a/src/language/stats/oneway.q +++ b/src/language/stats/oneway.q @@ -288,17 +288,17 @@ show_anova_table(void) struct hsh_table *group_hash = group_proc_get (vars[i])->group_hash; struct hsh_iterator g; struct group_statistics *gs; - double ssa=0; + double ssa = 0; const char *s = var_to_string(vars[i]); for (gs = hsh_first (group_hash,&g); gs != 0; gs = hsh_next(group_hash,&g)) { - ssa += (gs->sum * gs->sum)/gs->n; + ssa += pow2 (gs->sum) / gs->n; } - ssa -= ( totals->sum * totals->sum ) / totals->n ; + ssa -= pow2 (totals->sum) / totals->n; tab_text (t, 0, i * 3 + 1, TAB_LEFT | TAT_TITLE, s); tab_text (t, 1, i * 3 + 1, TAB_LEFT | TAT_TITLE, _("Between Groups")); @@ -310,7 +310,7 @@ show_anova_table(void) { struct group_proc *gp = group_proc_get (vars[i]); - const double sst = totals->ssq - ( totals->sum * totals->sum) / totals->n ; + const double sst = totals->ssq - pow2 (totals->sum) / totals->n ; const double df1 = gp->n_groups - 1; const double df2 = totals->n - gp->n_groups ; const double msa = ssa / df1; @@ -333,7 +333,6 @@ show_anova_table(void) tab_float (t, 4, i * 3 + 1, TAB_RIGHT, msa, 8, 3); tab_float (t, 4, i * 3 + 2, TAB_RIGHT, gp->mse, 8, 3); - { const double F = msa/gp->mse ; @@ -343,9 +342,7 @@ show_anova_table(void) /* The significance */ tab_float (t, 6, i * 3 + 1, 0, gsl_cdf_fdist_Q(F,df1,df2), 8, 3); } - } - } @@ -447,17 +444,17 @@ show_descriptives(void) tab_float (t, 2, row + count, 0, gs->n, 8,0); - tab_float (t, 3, row + count, 0, gs->mean,8,2); + tab_float (t, 3, row + count, 0, gs->mean, 8, 2); - tab_float (t, 4, row + count, 0, gs->std_dev,8,2); + tab_float (t, 4, row + count, 0, gs->std_dev, 8, 2); std_error = gs->std_dev/sqrt(gs->n) ; tab_float (t, 5, row + count, 0, - std_error, 8,2); + std_error, 8, 2); /* Now the confidence interval */ - T = gsl_cdf_tdist_Qinv(q,gs->n - 1); + T = gsl_cdf_tdist_Qinv(q, gs->n - 1); tab_float(t, 6, row + count, 0, gs->mean - T * std_error, 8, 2); @@ -761,13 +758,13 @@ show_contrast_tests(short *bad_contrast) const double coef = subc_list_double_at(&cmd.dl_contrast[i], ci); struct group_statistics *gs = group_stat_array[ci]; - const double winv = (gs->std_dev * gs->std_dev) / gs->n; + const double winv = pow2 (gs->std_dev) / gs->n; contrast_value += coef * gs->mean; coef_msq += (coef * coef) / gs->n ; - sec_vneq += (coef * coef) * (gs->std_dev * gs->std_dev ) /gs->n ; + sec_vneq += (coef * coef) * pow2 (gs->std_dev) /gs->n ; df_numerator += (coef * coef) * winv; df_denominator += pow2((coef * coef) * winv) / (gs->n - 1); @@ -783,7 +780,7 @@ show_contrast_tests(short *bad_contrast) cmd.sbc_contrast, TAB_RIGHT, contrast_value, 8,2); - std_error_contrast = sqrt(grp_data->mse * coef_msq); + std_error_contrast = sqrt (grp_data->mse * coef_msq); /* Std. Error */ tab_float (t, 4, (v * lines_per_variable) + i + 1, @@ -980,9 +977,9 @@ run_oneway (struct cmd_oneway *cmd, { struct group_statistics *totals = &gp->ugs; - totals->n+=weight; - totals->sum+=weight * val->f; - totals->ssq+=weight * val->f * val->f; + totals->n += weight; + totals->sum += weight * val->f; + totals->ssq += weight * pow2 (val->f); if ( val->f * weight < totals->minimum ) totals->minimum = val->f * weight; @@ -990,9 +987,9 @@ run_oneway (struct cmd_oneway *cmd, if ( val->f * weight > totals->maximum ) totals->maximum = val->f * weight; - gs->n+=weight; - gs->sum+=weight * val->f; - gs->ssq+=weight * val->f * val->f; + gs->n += weight; + gs->sum += weight * val->f; + gs->ssq += weight * pow2 (val->f); if ( val->f * weight < gs->minimum ) gs->minimum = val->f * weight; @@ -1043,31 +1040,27 @@ postcalc ( struct cmd_oneway *cmd UNUSED ) gs != 0; gs = hsh_next(group_hash,&g)) { - gs->mean=gs->sum / gs->n; + gs->mean = gs->sum / gs->n; gs->s_std_dev= sqrt( - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + gs->ssq / gs->n - pow2 (gs->mean) ) ; gs->std_dev= sqrt( - gs->n/(gs->n-1) * - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + gs->n / (gs->n - 1) * + ( gs->ssq / gs->n - pow2 (gs->mean)) ) ; - gs->se_mean = gs->std_dev / sqrt(gs->n); - gs->mean_diff= gs->sum_diff / gs->n; - + gs->se_mean = gs->std_dev / sqrt (gs->n); + gs->mean_diff = gs->sum_diff / gs->n; } - - totals->mean = totals->sum / totals->n; totals->std_dev= sqrt( - totals->n/(totals->n-1) * - ( (totals->ssq / totals->n ) - totals->mean * totals->mean ) + totals->n / (totals->n - 1) * + (totals->ssq / totals->n - pow2 (totals->mean)) ) ; - totals->se_mean = totals->std_dev / sqrt(totals->n); - + totals->se_mean = totals->std_dev / sqrt (totals->n); } } diff --git a/src/language/stats/t-test.q b/src/language/stats/t-test.q index c51d3bf2..116f04b4 100644 --- a/src/language/stats/t-test.q +++ b/src/language/stats/t-test.q @@ -1459,7 +1459,7 @@ common_calc (const struct dictionary *dict, gs->n += weight; gs->sum += weight * val->f; - gs->ssq += weight * val->f * val->f; + gs->ssq += weight * pow2 (val->f); } } return 0; @@ -1496,12 +1496,12 @@ common_postcalc (struct cmd_t_test *cmd) gs->mean=gs->sum / gs->n; gs->s_std_dev= sqrt ( - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + ( (gs->ssq / gs->n ) - pow2 (gs->mean)) ) ; gs->std_dev= sqrt ( gs->n/ (gs->n-1) * - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + ( (gs->ssq / gs->n ) - pow2 (gs->mean)) ) ; gs->se_mean = gs->std_dev / sqrt (gs->n); @@ -1772,12 +1772,12 @@ group_postcalc ( struct cmd_t_test *cmd ) gs->mean = gs->sum / gs->n; gs->s_std_dev= sqrt ( - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + ( (gs->ssq / gs->n ) - pow2 (gs->mean)) ) ; gs->std_dev= sqrt ( gs->n/ (gs->n-1) * - ( (gs->ssq / gs->n ) - gs->mean * gs->mean ) + ( (gs->ssq / gs->n ) - pow2 (gs->mean)) ) ; gs->se_mean = gs->std_dev / sqrt (gs->n); diff --git a/src/math/ts/innovations.c b/src/math/ts/innovations.c index 553e20e8..b9a7cf22 100644 --- a/src/math/ts/innovations.c +++ b/src/math/ts/innovations.c @@ -160,7 +160,7 @@ innovations_update_scale (struct innovations_estimate *est, double *theta, for (j = 0; j < i; j++) { k = i - j - 1; - result -= theta[k] * theta[k] * est->scale[j]; + result -= pow2 (theta[k]) * est->scale[j]; } est->scale[i] = result; }