static GnmValue * gnumeric_bessely (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); gnm_float y = value_get_as_float (argv[1]); return value_new_float (gnm_bessel_y (x, y)); }
static GnmValue * gnumeric_besselk (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); gnm_float order = value_get_as_float (argv[1]); /* the order */ return value_new_float (gnm_bessel_k (x, order)); }
static GnmValue * gnumeric_randfdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float nu1 = value_get_as_float (argv[0]); gnm_float nu2 = value_get_as_float (argv[1]); return value_new_float (random_fdist (nu1, nu2)); }
static GnmValue * gnumeric_randexppow (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); gnm_float b = value_get_as_float (argv[1]); return value_new_float (random_exppow (a, b)); }
static GnmValue * gnumeric_randnormtail (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); gnm_float sigma = value_get_as_float (argv[1]); return value_new_float (random_gaussian_tail (a, sigma)); }
static GnmValue * gnumeric_gestep (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); gnm_float y = argv[1] ? value_get_as_float (argv[1]) : 0; return value_new_int (x >= y); }
static GnmValue * gnumeric_randlognorm (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float zeta = value_get_as_float (argv[0]); gnm_float sigma = value_get_as_float (argv[1]); return value_new_float (random_lognormal (zeta, sigma)); }
static CritType criteria_inspect_values (GnmValue const *x, gnm_float *xr, gnm_float *yr, GnmCriteria *crit, gboolean coerce_to_float) { GnmValue const *y = crit->x; if (x == NULL || y == NULL) return CRIT_NULL; switch (y->v_any.type) { case VALUE_BOOLEAN: /* If we're searching for a bool -- even one that is from a string search value -- we match only bools. */ if (!VALUE_IS_BOOLEAN (x)) return CRIT_WRONGTYPE; *xr = value_get_as_float (x); *yr = value_get_as_float (y); return CRIT_FLOAT; case VALUE_EMPTY: return CRIT_WRONGTYPE; case VALUE_STRING: if (!VALUE_IS_STRING (x)) return CRIT_WRONGTYPE; return CRIT_STRING; default: g_warning ("This should not happen. Please report."); return CRIT_WRONGTYPE; case VALUE_FLOAT: { GnmValue *vx; *yr = value_get_as_float (y); if (VALUE_IS_BOOLEAN (x) || VALUE_IS_ERROR (x)) return CRIT_WRONGTYPE; else if (VALUE_IS_FLOAT (x)) { *xr = value_get_as_float (x); return CRIT_FLOAT; } if (!coerce_to_float) return CRIT_WRONGTYPE; vx = format_match (value_peek_string (x), NULL, crit->date_conv); if (VALUE_IS_EMPTY (vx) || VALUE_IS_BOOLEAN (y) != VALUE_IS_BOOLEAN (vx)) { value_release (vx); return CRIT_WRONGTYPE; } *xr = value_get_as_float (vx); value_release (vx); return CRIT_FLOAT; } } }
static GnmValue * gnumeric_randstdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float nu = value_get_as_float (argv[0]); gnm_float alpha = argv[1] ? value_get_as_float (argv[1]) : 0.; return ((alpha == 0.) ? value_new_float (random_tdist (nu)) : value_new_float (random_skew_tdist (nu, alpha)));; }
static GnmValue * gnumeric_randnorm (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float mean = value_get_as_float (argv[0]); gnm_float stdev = value_get_as_float (argv[1]); if (stdev < 0) return value_new_error_NUM (ei->pos); return value_new_float (stdev * random_normal () + mean); }
static GnmValue * gnumeric_randnegbinom (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float p = value_get_as_float (argv[0]); gnm_float failures = value_get_as_float (argv[1]); if (p < 0 || p > 1 || failures < 1) return value_new_error_NUM (ei->pos); return value_new_float (random_negbinom (p, gnm_floor (failures))); }
static GnmValue * gnumeric_randbinom (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float p = value_get_as_float (argv[0]); gnm_float trials = value_get_as_float (argv[1]); if (p < 0 || p > 1 || trials < 0) return value_new_error_NUM (ei->pos); return value_new_float (random_binomial (p, gnm_floor (trials))); }
static GnmValue * gnumeric_randgamma (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); gnm_float b = value_get_as_float (argv[1]); if (a <= 0) return value_new_error_NUM (ei->pos); return value_new_float (random_gamma (a, b)); }
static GnmValue * gnumeric_randuniform (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); gnm_float b = value_get_as_float (argv[1]); if (a > b) return value_new_error_NUM (ei->pos); return value_new_float (a + ( random_01 () * (b - a) ) ); }
static GnmValue * gnumeric_randhyperg (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float n1 = value_get_as_float (argv[0]); gnm_float n2 = value_get_as_float (argv[1]); gnm_float t = value_get_as_float (argv[2]); return value_new_float (random_hypergeometric (gnm_floor (n1), gnm_floor (n2), gnm_floor (t))); }
static GnmValue * gnumeric_randlevy (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float c = value_get_as_float (argv[0]); gnm_float alpha = value_get_as_float (argv[1]); gnm_float beta = argv[2] == NULL ? 0 : value_get_as_float (argv[1]); if (alpha <= 0 || alpha > 2 || beta < -1 || beta > 1) return value_new_error_NUM (ei->pos); return value_new_float (random_levy_skew (c, alpha, beta)); }
static GnmValue * gnumeric_randgumbel (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); gnm_float b = value_get_as_float (argv[1]); gnm_float type = argv[2] ? value_get_as_float (argv[2]) : 1; if (type == 1) return value_new_float (random_gumbel1 (a, b)); else if (type == 2) return value_new_float (random_gumbel2 (a, b)); else return value_new_error_NUM (ei->pos); }
static GnmValue * gnumeric_erf (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float lower = value_get_as_float (argv[0]); gnm_float ans; if (argv[1]) { gnm_float upper = value_get_as_float (argv[1]); ans = 2 * pnorm2 (lower * M_SQRT2gnum, upper * M_SQRT2gnum); } else ans = gnm_erf (lower); return value_new_float (ans); }
static GnmValue * gnumeric_randbetween (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float bottom = value_get_as_float (argv[0]); gnm_float top = value_get_as_float (argv[1]); if (bottom > top) return value_new_error_NUM (ei->pos); /* Bottom is ceiled, top floored. Neither is truncated. */ bottom = gnm_ceil (bottom); top = gnm_floor (top); return value_new_float (bottom + gnm_floor ((top + 1.0 - bottom) * random_01 ())); }
static gboolean gnm_nlsolve_get_initial_solution (GnmNlsolve *nl, GError **err) { GnmSolver *sol = nl->parent; const int n = nl->vars->len; int i; if (gnm_solver_check_constraints (sol)) goto got_it; /* More? */ g_set_error (err, go_error_invalid (), 0, _("The initial values do not satisfy the constraints.")); return FALSE; got_it: for (i = 0; i < n; i++) { GnmCell *cell = g_ptr_array_index (nl->vars, i); nl->xk[i] = nl->x0[i] = value_get_as_float (cell->value); } nl->yk = get_value (nl); gnm_nlsolve_set_solution (nl); return TRUE; }
static GnmValue * gnumeric_randexp (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); return value_new_float (random_exponential (x)); }
static GnmValue * gnumeric_erfc (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); return value_new_float (gnm_erfc (x)); }
static GnmValue * gnumeric_randrayleigh (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float sigma = value_get_as_float (argv[0]); return value_new_float (random_rayleigh (sigma)); }
static GnmValue * gnumeric_randtdist (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float nu = value_get_as_float (argv[0]); return value_new_float (random_tdist (nu)); }
static GnmValue * gnumeric_randlogistic (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); return value_new_float (random_logistic (a)); }
/* * We need a horizontal strip of 5 cells containing: * * 0. Formula cell. * 1: X value cell. * 2: Y target value. * 3: Min value. * 4: Max value. */ static void dialog_goal_seek_test (Sheet *sheet, const GnmRange *range) { GoalSeekState state; GnmCell *cell; int r, c; GoalSeekStatus status; g_return_if_fail (range->start.row == range->end.row); g_return_if_fail (range->start.col + 4 == range->end.col); memset (&state, 0, sizeof (state)); r = range->start.row; c = range->start.col; state.wb = sheet->workbook; state.sheet = sheet; state.set_cell = sheet_cell_fetch (sheet, c + 0, r); state.change_cell = sheet_cell_fetch (sheet, c + 1, r); state.old_value = value_dup (state.change_cell->value); cell = sheet_cell_fetch (sheet, c + 2, r); state.target_value = value_get_as_float (cell->value); cell = sheet_cell_fetch (sheet, c + 3, r); state.xmin = VALUE_IS_EMPTY (cell->value) ? -max_range_val : value_get_as_float (cell->value); cell = sheet_cell_fetch (sheet, c + 4, r); state.xmax = VALUE_IS_EMPTY (cell->value) ? max_range_val : value_get_as_float (cell->value); status = gnumeric_goal_seek (&state); if (status == GOAL_SEEK_OK) { /* Nothing */ } else { sheet_cell_set_value (state.change_cell, value_new_error_VALUE (NULL)); } value_release (state.old_value); }
/** * paste_cell: * @target_col: Column to put the cell into * @target_row: Row to put the cell into. * @src: A #GnmCelCopy with the content to paste * @paste_flags: Bit mask that describes the paste options. * * Pastes a cell in the spreadsheet. */ static void paste_cell (int target_col, int target_row, GnmCellCopy const *src, const struct paste_cell_data *dat) { Sheet *dst_sheet = dat->pt->sheet; int paste_flags = dat->pt->paste_flags; if (paste_flags & PASTE_OPER_MASK) paste_cell_with_operation (dst_sheet, target_col, target_row, &dat->rinfo, src, paste_flags); else { GnmCell *dst = sheet_cell_fetch (dst_sheet, target_col, target_row); if (NULL != src->texpr && (paste_flags & PASTE_CONTENTS)) { GnmExprTop const *relo = gnm_expr_top_relocate ( src->texpr, &dat->rinfo, FALSE); if (paste_flags & PASTE_TRANSPOSE) { GnmExprTop const *trelo = gnm_expr_top_transpose (relo ? relo : src->texpr); if (trelo) { if (relo) gnm_expr_top_unref (relo); relo = trelo; } } else if (!relo && gnm_expr_top_is_array_corner (src->texpr)) { /* We must not share array expressions. */ relo = gnm_expr_top_new (gnm_expr_copy (src->texpr->expr)); } gnm_cell_set_expr_and_value (dst, relo ? relo : src->texpr, value_dup (src->val), TRUE); if (NULL != relo) gnm_expr_top_unref (relo); } else { GnmValue *newval = NULL; GnmValue const *oldval = src->val; if (dat->translate_dates && oldval && VALUE_IS_FLOAT (oldval)) { GOFormat const *fmt = VALUE_FMT (oldval) ? VALUE_FMT (oldval) : gnm_style_get_format (gnm_cell_get_style (dst)); if (go_format_is_date (fmt) > 0) { gnm_float fnew = go_date_conv_translate (value_get_as_float (oldval), dat->cr->date_conv, workbook_date_conv (dst_sheet->workbook)); newval = value_new_float (fnew); value_set_fmt (newval, VALUE_FMT (oldval)); } } if (!newval) newval = value_dup (src->val); gnm_cell_set_value (dst, newval); } } }
static GnmValue * gnumeric_randcauchy (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float a = value_get_as_float (argv[0]); if (a < 0) return value_new_error_NUM (ei->pos); return value_new_float (random_cauchy (a)); }
static GnmValue * gnumeric_randpoisson (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float x = value_get_as_float (argv[0]); if (x < 0) return value_new_error_NUM (ei->pos); return value_new_float (random_poisson (x)); }
static GnmValue * gnumeric_randlog (GnmFuncEvalInfo *ei, GnmValue const * const *argv) { gnm_float p = value_get_as_float (argv[0]); if (p < 0 || p > 1) return value_new_error_NUM (ei->pos); return value_new_float (random_logarithmic (p)); }