~ubuntu-branches/ubuntu/feisty/gnumeric/feisty-updates

« back to all changes in this revision

Viewing changes to plugins/fn-math/functions.c

  • Committer: Bazaar Package Importer
  • Author(s): Gauvain Pocentek
  • Date: 2006-11-14 14:02:03 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20061114140203-iv3j2aii3vch6isl
Tags: 1.7.2-1ubuntu1
* Merge with debian experimental:
  - debian/control, debian/*-gtk-*, debian/rules,
    debian/shlibs.local: Xubuntu changes for
    gtk/gnome multibuild.
  - run intltool-update in po*
  - Build Depend on intltool

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
} math_sums_t;
50
50
 
51
51
static GnmValue *
52
 
callback_function_sumxy (Sheet *sheet, int col, int row,
53
 
                         GnmCell *cell, void *user_data)
 
52
callback_function_sumxy (GnmCellIter const *iter, gpointer user)
54
53
{
55
 
        if (cell == NULL)
 
54
        GnmCell *cell;
 
55
        if (NULL == (cell = iter->cell))
56
56
                return NULL;
57
57
        cell_eval (cell);
58
58
 
59
59
        if (VALUE_IS_NUMBER (cell->value)) {
60
 
                math_sums_t *mm = user_data;
 
60
                math_sums_t *mm = user;
61
61
                gnm_float *p = g_new (gnm_float, 1);
62
62
                *p = value_get_as_float (cell->value);
63
63
                mm->list = g_slist_append (mm->list, p);
131
131
}
132
132
 
133
133
static GnmValue *
134
 
gnumeric_gcd (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
134
gnumeric_gcd (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
135
135
{
136
136
        return float_range_function (argc, argv, ei,
137
137
                                     range_gcd,
200
200
}
201
201
 
202
202
static GnmValue *
203
 
gnumeric_lcm (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
203
gnumeric_lcm (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
204
204
{
205
205
        return float_range_function (argc, argv, ei,
206
206
                                     range_lcm,
230
230
};
231
231
 
232
232
static GnmValue *
233
 
gnumeric_hypot (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
233
gnumeric_hypot (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
234
234
{
235
235
        return float_range_function (argc, argv, ei,
236
236
                                     range_hypot,
559
559
} CountIfClosure;
560
560
 
561
561
static GnmValue *
562
 
cb_countif (Sheet *sheet, int col, int row, GnmCell *cell, CountIfClosure *res)
 
562
cb_countif (GnmCellIter const *iter, CountIfClosure *res)
563
563
{
564
 
        if (cell == NULL)
565
 
                return NULL;
566
 
        cell_eval (cell);
567
 
 
568
 
        if (VALUE_IS_NUMBER (cell->value) || VALUE_IS_STRING (cell->value)) {
569
 
                if ((res->test) (cell->value, res->test_value))
 
564
        GnmCell *cell;
 
565
        if (NULL != (cell = iter->cell)) {
 
566
                cell_eval (cell);
 
567
                if ((VALUE_IS_NUMBER (cell->value) ||
 
568
                     VALUE_IS_STRING (cell->value)) &&
 
569
                    (res->test) (cell->value, res->test_value))
570
570
                        res->count++;
571
571
        }
572
572
 
595
595
        res.count = 0;
596
596
        parse_criteria (argv[1], &res.test, &res.test_value, &iter_flags,
597
597
                workbook_date_conv (ei->pos->sheet->workbook));
 
598
#warning 2006/May/31  Why do we not filter non-existent as a flag, rather than checking for NULL in cb_countif
598
599
        problem = sheet_foreach_cell_in_range (sheet, iter_flags,
599
600
                r->cell.a.col, r->cell.a.row, r->cell.b.col, r->cell.b.row,
600
601
                (CellIterFunc) &cb_countif, &res);
642
643
} SumIfClosure;
643
644
 
644
645
static GnmValue *
645
 
cb_sumif (Sheet *sheet, int col, int row, GnmCell *cell,
646
 
          SumIfClosure *res)
 
646
cb_sumif (GnmCellIter const *iter, SumIfClosure *res)
647
647
{
648
 
        if (cell == NULL)
 
648
        GnmCell *cell;
 
649
        if (NULL == (cell = iter->cell))
649
650
                return NULL;
650
651
        cell_eval (cell);
651
652
 
652
 
        if (VALUE_IS_NUMBER (cell->value) || VALUE_IS_STRING (cell->value)) {
653
 
                if ((res->test) (cell->value, res->test_value)) {
654
 
                        if (NULL != res->target_sheet) {
655
 
                                cell = sheet_cell_get (res->target_sheet,
656
 
                                        col + res->offset.col, row + res->offset.row);
657
 
                                if (cell != NULL) {
658
 
                                        cell_eval (cell);
659
 
                                        switch (cell->value->type) {
660
 
                                        case VALUE_FLOAT:
661
 
                                                /* FIXME: Check bools.  */
662
 
                                                res->sum += value_get_as_float (cell->value);
663
 
                                                break;
664
 
                                        default:
665
 
                                                break;
666
 
                                        }
 
653
        if ((VALUE_IS_NUMBER (cell->value) || VALUE_IS_STRING (cell->value)) &&
 
654
            (res->test) (cell->value, res->test_value)) {
 
655
                if (NULL != res->target_sheet) {
 
656
                        cell = sheet_cell_get (res->target_sheet,
 
657
                                iter->pp.eval.col + res->offset.col,
 
658
                                iter->pp.eval.row + res->offset.row);
 
659
                        if (cell != NULL) {
 
660
                                cell_eval (cell);
 
661
                                switch (cell->value->type) {
 
662
                                case VALUE_FLOAT:
 
663
                                        /* FIXME: Check bools.  */
 
664
                                        res->sum += value_get_as_float (cell->value);
 
665
                                        break;
 
666
                                default:
 
667
                                        break;
667
668
                                }
668
 
                        } else
669
 
                                /* FIXME: Check bools.  */
670
 
                                res->sum += value_get_as_float (cell->value);
671
 
                }
 
669
                        }
 
670
                } else
 
671
                        /* FIXME: Check bools.  */
 
672
                        res->sum += value_get_as_float (cell->value);
672
673
        }
673
674
 
674
675
        return NULL;
717
718
        res.sum = 0.;
718
719
        parse_criteria (argv[1], &res.test, &res.test_value, &iter_flags,
719
720
                workbook_date_conv (ei->pos->sheet->workbook));
 
721
#warning 2006/May/31  Why do we not filter non-existent as a flag, rather than checking for NULL in cb_sumif
720
722
        problem = sheet_foreach_cell_in_range (sheet, iter_flags,
721
723
                r->cell.a.col, r->cell.a.row, col_end, row_end,
722
724
                (CellIterFunc) &cb_sumif, &res);
1044
1046
/***************************************************************************/
1045
1047
 
1046
1048
static GnmFuncHelp const help_floor[] = {
1047
 
        { GNM_FUNC_HELP_OLD,
1048
 
        F_("@FUNCTION=FLOOR\n"
1049
 
           "@SYNTAX=FLOOR(x[,significance])\n"
1050
 
 
1051
 
           "@DESCRIPTION="
 
1049
        { GNM_FUNC_HELP_NAME, F_("FLOOR:rounds down.") },
 
1050
        { GNM_FUNC_HELP_ARG, F_("x:value.") },
 
1051
        { GNM_FUNC_HELP_ARG, F_("significance:base multiple (defaults to 1 for @x > 0 and -1 for @x <0)") },
 
1052
        { GNM_FUNC_HELP_SEEALSO, "CEIL,CEILING,ABS,INT,MOD" },
 
1053
        { GNM_FUNC_HELP_DESCRIPTION, F_(
1052
1054
           "FLOOR function rounds @x down to the next nearest multiple "
1053
 
           "of @significance.\n\n"
1054
 
           "* @significance defaults to 1.\n"
1055
 
           "* This function is Excel compatible.\n"
1056
 
           "\n"
1057
 
           "@EXAMPLES=\n"
1058
 
           "FLOOR(0.5) equals 0.\n"
1059
 
           "FLOOR(5,2) equals 4.\n"
1060
 
           "FLOOR(-5,-2) equals -4.\n"
1061
 
           "FLOOR(-5,2) equals #NUM!.\n"
1062
 
           "\n"
1063
 
           "@SEEALSO=CEIL, CEILING, ABS, INT, MOD")
1064
 
        },
 
1055
           "of @significance.") },
 
1056
        { GNM_FUNC_HELP_EXAMPLES, F_("FLOOR(0.5) equals 0.") },
 
1057
        { GNM_FUNC_HELP_EXAMPLES, F_("FLOOR(5,2) equals 4.") },
 
1058
        { GNM_FUNC_HELP_EXAMPLES, F_("FLOOR(-5,-2) equals -4.") },
 
1059
        { GNM_FUNC_HELP_EXAMPLES, F_("FLOOR(-5,2) equals #NUM!.") },
1065
1060
        { GNM_FUNC_HELP_END }
1066
1061
};
1067
1062
 
1501
1496
};
1502
1497
 
1503
1498
static GnmValue *
1504
 
gnumeric_suma (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
1499
gnumeric_suma (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
1505
1500
{
1506
1501
        return float_range_function (argc, argv, ei,
1507
1502
                                     range_sum,
1535
1530
 
1536
1531
 
1537
1532
static GnmValue *
1538
 
gnumeric_sumsq (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
1533
gnumeric_sumsq (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
1539
1534
{
1540
1535
        return float_range_function (argc, argv, ei,
1541
1536
                                     range_sumsq,
1567
1562
 
1568
1563
 
1569
1564
static GnmValue *
1570
 
gnumeric_multinomial (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
1565
gnumeric_multinomial (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
1571
1566
{
1572
1567
        return float_range_function (argc, argv, ei,
1573
1568
                                     range_multinomial,
1598
1593
};
1599
1594
 
1600
1595
static GnmValue *
1601
 
gnumeric_g_product (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
1596
gnumeric_g_product (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
1602
1597
{
1603
1598
        return float_range_function (argc, argv, ei,
1604
1599
                                     range_product,
2891
2886
 
2892
2887
 
2893
2888
static GnmValue *
2894
 
gnumeric_seriessum (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
2889
gnumeric_seriessum (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
2895
2890
{
2896
2891
        return float_range_function (argc, argv, ei,
2897
2892
                                     range_seriessum,
2926
2921
 
2927
2922
 
2928
2923
static GnmValue *
2929
 
cb_function_mmult_validate (Sheet *sheet, int col, int row,
2930
 
                             GnmCell *cell, void *user_data)
 
2924
cb_function_mmult_validate (GnmCellIter const *iter, gpointer user)
2931
2925
{
2932
 
        int *item_count = user_data;
 
2926
        GnmCell *cell = iter->cell;
 
2927
        int *item_count = user;
2933
2928
 
2934
2929
        cell_eval (cell);
2935
2930
        if (!VALUE_IS_NUMBER (cell->value))
3198
3193
};
3199
3194
 
3200
3195
static GnmValue *
3201
 
gnumeric_sumproduct (FunctionEvalInfo *ei, int argc, const GnmExprConstPtr *argv)
 
3196
gnumeric_sumproduct (FunctionEvalInfo *ei, int argc, GnmExprConstPtr const *argv)
3202
3197
{
3203
3198
        gnm_float **data;
3204
3199
        GnmValue *result;