functions.c 31.8 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1
/*
2
 * fn-math.c:  Built in mathematical functions and functions registration
Arturo Espinosa's avatar
Arturo Espinosa committed
3
 *
Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
4
 * Authors:
Arturo Espinosa's avatar
Arturo Espinosa committed
5
 *  Miguel de Icaza (miguel@gnu.org)
Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
6
 *  Jukka-Pekka Iivonen (iivonen@iki.fi)
Arturo Espinosa's avatar
Arturo Espinosa committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 */
#include <config.h>
#include <gnome.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"

/* Some forward declarations */
static Value *gnumeric_sum         (void *tsheet, GList *expr_node_list,
				    int eval_col, int eval_row,
				    char **error_string);

static Value *gnumeric_count       (void *tsheet, GList *expr_node_list,
				    int eval_col, int eval_row,
				    char **error_string);

Donnie Barnes's avatar
Donnie Barnes committed
25
26
27
#if 0
/* help template */
static char *help_ = {
28
29
	N_("@FUNCTION=NAME\n"
	   "@SYNTAX=(b1, b2, ...)\n"
Donnie Barnes's avatar
Donnie Barnes committed
30

31
	   "@DESCRIPTION"
Donnie Barnes's avatar
Donnie Barnes committed
32
	   ""
33
	   "\n"
Donnie Barnes's avatar
Donnie Barnes committed
34
35
36

	   ""
	   ""
37
	   "\n"
Donnie Barnes's avatar
Donnie Barnes committed
38
39
40
41
	   
	   ""
	   ""
	   ""
42
43
	   ""
	   "@SEEALSO=")
Donnie Barnes's avatar
Donnie Barnes committed
44
45
46
47
};

#endif

48
49
50
static char *help_abs = {
	N_("@FUNCTION=ABS\n"
	   "@SYNTAX=ABS(b1)\n"
51

52
53
54
	   "@DESCRIPTION=Implements the Absolute Value function:  the result is "
	   "to drop the negative sign (if present).  This can be done for "
	   "integers and floating point numbers."
55
	   "\n"
56
	   "Performing this function on a string or empty cell simply does nothing."
57
	   "\n"
58
	   "@SEEALSO=CEIL, FLOOR")
59
60
};

61
62
63
64
65
static Value *
gnumeric_abs (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	return value_float (fabs (value_get_as_double (argv [0])));
}
66
67

static char *help_acos = {
68
	N_("@FUNCTION=ACOS\n"
69
	   "@SYNTAX=ACOS(x)\n"
70

71
	   "@DESCRIPTION="
72
73
	   "The ACOS function calculates the arc cosine of x; that "
	   " is the value whose cosine is x.  If x  falls  outside  the "
74
75
	   " range -1 to 1, ACOS fails and returns the error 'acos - domain error'. "
	   " The value it returns is in radians. "
76
	   "\n"
77
78
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
79
80
	   "\n"
	   "@SEEALSO=COS, SIN, DEGREES, RADIANS")
81
82
};

83
84
85
86
static Value *
gnumeric_acos (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	float_t t;
Donnie Barnes's avatar
Donnie Barnes committed
87

88
89
90
91
92
93
94
95
96
97
	t = value_get_as_double (argv [0]);
	if ((t < -1.0) || (t > 1.0)){
		*error_string = _("acos - domain error");
		return NULL;
	}
	return value_float (acos (t));
}

static char *help_acosh = {
	N_("@FUNCTION=ACOSH\n"
98
	   "@SYNTAX=ACOSH(x)\n"
99
100
101

	   "@DESCRIPTION="
	   "The ACOSH  function  calculates  the inverse hyperbolic "
102
103
	   "cosine of x; that is the value whose hyperbolic cosine is "
	   "x. If x is less than 1.0, acosh() returns the error "
104
	   " 'acosh - domain error'"
Arturo Espinosa's avatar
Arturo Espinosa committed
105
	   "\n"
106
107
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
108
	   "\n"
109
	   "@SEEALSO=ACOS, DEGREES, RADIANS ")
Donnie Barnes's avatar
Donnie Barnes committed
110
111
};

112
113
114
115
116
117
118
119
120
121
122
123
124
static Value *
gnumeric_acosh (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	float_t t;

	t = value_get_as_double (argv [0]);
	if (t < 1.0){
		*error_string = _("acosh - domain error");
		return NULL;
	}
	return value_float (acosh (t));
}

Arturo Espinosa's avatar
Arturo Espinosa committed
125
static char *help_and = {
126
127
	N_("@FUNCTION=AND\n"
	   "@SYNTAX=AND(b1, b2, ...)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
128

129
	   "@DESCRIPTION=Implements the logical AND function: the result is TRUE "
Donnie Barnes's avatar
Donnie Barnes committed
130
	   "if all of the expression evaluates to TRUE, otherwise it returns "
131
	   "FALSE.\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
132

133
	   "b1, trough bN are expressions that should evaluate to TRUE or FALSE. "
Arturo Espinosa's avatar
Arturo Espinosa committed
134
	   "If an integer or floating point value is provided zero is considered "
135
	   "FALSE and anything else is TRUE.\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
136
137
138
139
	   
	   "If the values contain strings or empty cells those values are "
	   "ignored.  If no logical values are provided, then the error '#VALUE!' "
	   "is returned. "
140
	   "\n"
141
	   "@SEEALSO=OR, NOT")
Arturo Espinosa's avatar
Arturo Espinosa committed
142
143
};

144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
static int
callback_function_and (Sheet *sheet, Value *value, char **error_string, void *closure)
{
	Value *result = closure;
	
	switch (value->type){
	case VALUE_INTEGER:
		if (value->v.v_int == 0){
			result->v.v_int = 0;
			return FALSE;
		} else
			result->v.v_int = 1;
		break;

	case VALUE_FLOAT:
		if (value->v.v_float == 0.0){
			result->v.v_int = 0;
			return FALSE;
		} else
			result->v.v_int = 1;

	default:
		/* ignore strings */
167
		break;
168
169
170
171
172
	}
	
	return TRUE;
}

Arturo Espinosa's avatar
Arturo Espinosa committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
static Value *
gnumeric_and (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *result;
	Sheet *sheet = (Sheet *) tsheet;

	result = g_new (Value, 1);
	result->type = VALUE_INTEGER;
	result->v.v_int = -1;

	function_iterate_argument_values (sheet, callback_function_and,
					  result, expr_node_list,
					  eval_col, eval_row, error_string);

	/* See if there was any value worth using */
	if (result->v.v_int == -1){
		value_release (result);
		*error_string = _("#VALUE");
		return NULL;
	}
	return result;
}

196
197
static char *help_asin = {
	N_("@FUNCTION=ASIN\n"
198
	   "@SYNTAX=ASIN(x)\n"
199
200

	   "@DESCRIPTION="
201
202
	   "The ASIN function calculates the arc sine of x; that is "
	   "the value whose sine is x. If x falls outside  the  range "
203
204
205
206
207
208
209
210
	   "-1 to 1, ASIN fails and returns the error 'asin - domain error'   "
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=SIN, COS, ASINH, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
211
static Value *
212
gnumeric_asin (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
213
214
215
216
217
218
219
220
{
	float_t t;

	t = value_get_as_double (argv [0]);
	if ((t < -1.0) || (t > 1.0)){
		*error_string = _("asin - domain error");
		return NULL;
	}
221
	return value_float (asin (t));
Arturo Espinosa's avatar
Arturo Espinosa committed
222
223
}

224
225
static char *help_asinh = {
	N_("@FUNCTION=ASINH\n"
226
	   "@SYNTAX=ASINH(x)\n"
227
228

	   "@DESCRIPTION="
229
230
	   "The ASINH  function  calculates  the inverse hyperbolic "
	   " sine of x; that is the value whose hyperbolic sine is x. "
231
232
233
234
235
236
237
238
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=ASIN, SIN, COS, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
239
static Value *
240
gnumeric_asinh (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
241
{
242
243
	return value_float (asinh (value_get_as_double (argv [0])));
}
Arturo Espinosa's avatar
Arturo Espinosa committed
244

245
246
static char *help_atan = {
	N_("@FUNCTION=ATAN\n"
247
	   "@SYNTAX=ATAN(x)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
248

249
	   "@DESCRIPTION="
250
251
	   "The ATAN function calculates the arc tangent of x; that "
	   " is the value whose tangent is x."
252
253
254
255
256
257
258
259
260
	   "Return value is in radians."
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"

	   "@SEEALSO=TAN, COS, SIN, DEGREES, RADIANS")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
261
262

static Value *
263
gnumeric_atan (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
264
{
265
	return value_float (atan (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
266
267
}

268
269
static char *help_atanh = {
	N_("@FUNCTION=ATANH\n"
270
	   "@SYNTAX=ATANH(x)\n"
271
272
273

	   "@DESCRIPTION="
	   "The  ATANH  function  calculates  the inverse hyperbolic "
274
275
	   "tangent of x; that is the value whose  hyperbolic  tangent "
	   "is  x.   If  the  absolute value of x is greater than 1.0, "
276
277
278
279
280
281
282
283
284
	   " ATANH returns an error of 'atanh: domain error'      "
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=ATAN, TAN, SIN, COS, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
285
static Value *
286
gnumeric_atanh (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
287
288
289
290
291
292
293
294
{
	float_t t;

	t = value_get_as_double (argv [0]);
	if ((t <= -1.0) || (t >= 1.0)){
		*error_string = _("atanh: domain error");
		return NULL;
	}
295
	return value_float (atanh (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
296
297
}

298
static char *help_atan2 = {
299
	N_("@FUNCTION=ATAN2\n"
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
	   "@SYNTAX=ATAN2(b1,b2)\n"

	   "@DESCRIPTION="
	   "The ATAN2 function calculates the arc tangent of the two "
	   "variables b1 and b2.  It is similar to calculating  the  arc "
	   "tangent  of b2 / b1, except that the signs of both arguments "
	   "are used to determine the quadrant of the result. "
	   "The result is in Radians."
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "\n"
	   "@SEEALSO=ATAN, ATANH, COS, SIN, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
315
static Value *
316
gnumeric_atan2 (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
317
{
318
319
	return value_float (atan2 (value_get_as_double (argv [0]),
				   value_get_as_double (argv [1])));
Arturo Espinosa's avatar
Arturo Espinosa committed
320
321
}

322
323
static char *help_average = {
	N_("@FUNCTION=AVERAGE\n"
324
	   "@SYNTAX=AVERAGE(value1, value2,...)\n"
325
326
327
328
329
330
331
332
333

	   "@DESCRIPTION="
	   "Computes the average of all the values and cells referenced in the "
	   "argument list.  This is equivalent to the sum of the arguments divided "
	   "by the count of the arguments."
	   "\n"
	   "@SEEALSO=SUM, COUNT")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
334
335
336
337
338
static Value *
gnumeric_average (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *result;
	Value *sum, *count;
339
340
	double c;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
341
342
343
344
345
	sum = gnumeric_sum (tsheet, expr_node_list, eval_col, eval_row, error_string);
	if (!sum)
		return NULL;
	
	count = gnumeric_count (tsheet, expr_node_list, eval_col, eval_row, error_string);
346
	if (!count){
Arturo Espinosa's avatar
Arturo Espinosa committed
347
348
349
350
		value_release (sum);
		return NULL;
	}

Arturo Espinosa's avatar
Arturo Espinosa committed
351
	c = value_get_as_double (count);
352
353
354
355
356
357
358
	
	if (c == 0.0){
		*error_string = "Division by zero";
		value_release (sum);
		return NULL;
	}
	
Arturo Espinosa's avatar
Arturo Espinosa committed
359
	result = value_float (value_get_as_double (sum) / c);
360

Arturo Espinosa's avatar
Arturo Espinosa committed
361
362
363
364
365
366
	value_release (count);
	value_release (sum);
	
	return result;
}

367
368
static char *help_ceil = {
	N_("@FUNCTION=CEIL\n"
369
	   "@SYNTAX=CEIL(x)\n"
370

371
372
	   "@DESCRIPTION=The CEIL function rounds x up to the next nearest "
	   "integer.\n"
373
374
375
376
377
378
379

	   "Performing this function on a string or empty cell simply does nothing."
	   "\n"
	   
	   "@SEEALSO=ABS, FLOOR, INT")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
380
static Value *
381
gnumeric_ceil (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
382
{
383
384
385
386
387
	return value_float (ceil (value_get_as_double (argv [0])));
}

static char *help_cos = {
	N_("@FUNCTION=COS\n"
388
	   "@SYNTAX=COS(x)\n"
389
390

	   "@DESCRIPTION="
391
	   "The  COS  function  returns  the cosine of x, where x is "
392
393
394
395
396
397
398
399
           "given in radians.  "
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=COSH, SIN, SINH, TAN, TANH, RADIANS, DEGREES")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
400
static Value *
401
gnumeric_cos (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
402
{
403
404
	return value_float (cos (value_get_as_double (argv [0])));
}
Arturo Espinosa's avatar
Arturo Espinosa committed
405

406
407
static char *help_cosh = {
	N_("@FUNCTION=COSH\n"
408
	   "@SYNTAX=COSH(x)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
409

410
	   "@DESCRIPTION="
411
412
413
	   "The COSH  function  returns the hyperbolic cosine of x, "
	   " which is defined mathematically as (exp(x) + exp(-x)) / 2.   "
	   " x is in radians. "
414
415
416
417
418
419
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=COS, SIN, SINH, TAN, TANH, RADIANS, DEGREES, EXP")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
420
421

static Value *
422
gnumeric_cosh (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
423
{
424
	return value_float (cosh (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
}

static int
callback_function_count (Sheet *sheet, Value *value, char **error_string, void *closure)
{
	Value *result = (Value *) closure;

	switch (value->type){
	case VALUE_INTEGER:
		result->v.v_int++;
		break;
		
	case VALUE_FLOAT:
		result->v.v_int++;
		break;
		
	default:
		break;
	}		
	return TRUE;
}

447
448
449
450
451
452
453
454
455
456
457
458
static char *help_count = {
	N_("@FUNCTION=COUNT\n"
	   "@SYNTAX=COUNT(b1, b2, ...)\n"

	   "@DESCRIPTION="
	   "Returns the total number of arguments passed."
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing."
	   "\n"
	   "@SEEALSO=AVERAGE")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
static Value *
gnumeric_count (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *result;
	Sheet *sheet = (Sheet *) tsheet;

	result = g_new (Value, 1);
	result->type = VALUE_INTEGER;
	result->v.v_int = 0;
	
	function_iterate_argument_values (sheet, callback_function_count, result, expr_node_list,
					  eval_col, eval_row, error_string);

	return result;
}

475
476
static char *help_degrees = {
	N_("@FUNCTION=DEGREES\n"
477
	   "@SYNTAX=DEGREES(x)\n"
478
479

	   "@DESCRIPTION="
480
481
	   "Computes the number of degrees equivalent to "
	   " x radians."
482
483
484
485
486
487
488
489
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "\n"
	   
	   "@SEEALSO=RADIANS, PI")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
490
static Value *
491
gnumeric_degrees (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
492
{
493
494
	return value_float ((value_get_as_double (argv [0]) * 180.0) / M_PI);
}
Arturo Espinosa's avatar
Arturo Espinosa committed
495

496
497
static char *help_exp = {
	N_("@FUNCTION=EXP\n"
498
	   "@SYNTAX=EXP(x)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
499

500
501
	   "@DESCRIPTION="
	   "Computes the value of e(the base of natural logarithmns) raised "
502
	   "to the power of x. "
503
504
505
506
507
	   "\n"
	   "Performing this function on a string or empty cell returns an error."
	   "\n"
	   "@SEEALSO=LOG, LOG2, LOG10")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
508
509

static Value *
510
gnumeric_exp (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
511
{
512
	return value_float (exp (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
513
514
}

515
516
517
518
519
520
521
522
static float_t
fact (int n)
{
	if (n == 0)
		return 1;
	return (n * fact (n - 1));
}

523
524
static char *help_fact = {
	N_("@FUNCTION=FACT\n"
525
	   "@SYNTAX=FACT(x)\n"
526
527

	   "@DESCRIPTION="
528
	   "Computes the factorial of x. ie, x!"
529
530
531
532
533
534
535
	   "\n"
	   "Performing this function on a string or empty cell returns an error"
	   "\n"
	   "\n"
	   "@SEEALSO=")
};

536
static Value *
537
gnumeric_fact (struct FunctionDefinition *id, Value *argv [], char **error_string)
538
539
{
	Value *res;
540
	float i;
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559

	switch (argv [0]->type){
	case VALUE_FLOAT:
		i = argv [0]->v.v_float;
		break;
	case VALUE_INTEGER:
		i = argv [0]->v.v_int;
		break;
	default:
		*error_string = "#NUM!";
		return NULL;
	}

	if (i < 0){
		*error_string = "#NUM!";
		return NULL;
	}
	
	res = g_new (Value, 1);
560
561
562
563
564
565
	if (i > 12){
		res->type = VALUE_FLOAT;
		res->v.v_float = exp (lgamma (i + 1));
	} else {
		res->type = VALUE_INTEGER;
		res->v.v_int = fact ((int)i);
566
567
568
569
	}
	return res;
}

Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
static char *help_combin = {
	N_("@FUNCTION=COMBIN\n"
	   "@SYNTAX=COMBIN(n,k)\n"

	   "@DESCRIPTION="
	   "Computes the number of combinations."
	   "\n"
	   "Performing this function on a non-integer or a negative number "
           "returns an error. Also if n is less than k returns an error."
	   "\n"
	   "\n"
	   "@SEEALSO=")
};

float_t
combin (int n, int k)
{
	return fact(n) / (fact(k) * fact(n-k));
}

static Value *
gnumeric_combin (struct FunctionDefinition *id, Value *argv [], char **error_string)
{
	Value *res;
	float_t n, k;

	if (argv [0]->type == VALUE_INTEGER &&
	    argv [1]->type == VALUE_INTEGER &&
	    argv[0]->v.v_int >= argv[1]->v.v_int){
		n = argv [0]->v.v_int;
		k = argv [1]->v.v_int;
	} else {
		*error_string = "#NUM!";
		return NULL;
	}
	
	res = g_new (Value, 1);
	res->type = VALUE_INTEGER;
	res->v.v_int = combin ((int)n, (int)k);
	return res;
}

612
613
static char *help_floor = {
	N_("@FUNCTION=FLOOR\n"
614
	   "@SYNTAX=FLOOR(x)\n"
615

616
	   "@DESCRIPTION=The FLOOR function rounds x down to the next nearest "
617
618
619
620
621
622
623
624
	   "integer."
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing."
	   "\n"
	   "@SEEALSO=CEIL, ABS, INT")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
625
static Value *
626
gnumeric_floor (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
627
{
628
629
	return value_float (floor (value_get_as_double (argv [0])));
}
Arturo Espinosa's avatar
Arturo Espinosa committed
630

631
632
633
static char *help_int = {
	N_("@FUNCTION=INT\n"
	   "@SYNTAX=INT(b1, b2, ...)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
634

635
636
637
	   "@DESCRIPTION="
	   "The INT function round b1 now to the nearest int. "
	   "Where 'nearest' implies being closer to zero. "
638
	   "Equivalent to FLOOR(b1) for b1 >0, amd CEIL(b1) "
639
640
641
642
643
644
645
	   "for b1 < 0. " 
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing."
	   ""
	   "\n"
	   "@SEEALSO=FLOOR, CEIL, ABS")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
646
647

static Value *
648
gnumeric_int (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
649
650
651
652
653
{
	float_t t;

	t = value_get_as_double (argv [0]);
	
654
	return value_float (t > 0.0 ? floor (t) : ceil (t));
Arturo Espinosa's avatar
Arturo Espinosa committed
655
656
}

657
658
static char *help_log = {
	N_("@FUNCTION=LOG\n"
659
	   "@SYNTAX=LOG(x)\n"
660
661

	   "@DESCRIPTION="
662
	   "Computes the natural logarithm  of x. "
663
664
665
666
667
668
	   "\n"
	   "Performing this function on a string or empty cell returns an error. "
	   "\n"
	   "@SEEALSO=EXP, LOG2, LOG10")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
669
static Value *
670
gnumeric_log (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
671
672
673
674
{
	float_t t;

	t = value_get_as_double (argv [0]);
675
	if (t <= 0.0){
Arturo Espinosa's avatar
Arturo Espinosa committed
676
677
678
		*error_string = _("log: domain error");
		return NULL;
	}
679
	return value_float (log (t));
Arturo Espinosa's avatar
Arturo Espinosa committed
680
681
}

682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
static char *help_power = {
	N_("@FUNCTION=POWER\n"
	   "@SYNTAX=POWER(x,y)\n"

	   "@DESCRIPTION="
	   "Returns the value of x raised to the power y"
	   "\n"
	   "Performing this function on a string or empty cell returns an error. "
	   "\n"
	   "@SEEALSO=EXP")
};

static Value *
gnumeric_power (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	return value_float (pow(value_get_as_double (argv [0]),
				value_get_as_double (argv [1]))) ;
}

701
static char *help_log2 = {
702
	N_("@FUNCTION=LOG2\n"
703
	   "@SYNTAX=LOG2(x)\n"
704
705

	   "@DESCRIPTION="
706
	   "Computes the base-2 logarithm  of x. "
707
708
709
710
711
712
	   "\n"
	   "Performing this function on a string or empty cell returns an error. "
	   "\n"
	   "@SEEALSO=EXP, LOG10, LOG")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
713
static Value *
714
gnumeric_log2 (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
715
716
717
718
{
	float_t t;

	t = value_get_as_double (argv [0]);
719
	if (t <= 0.0){
Arturo Espinosa's avatar
Arturo Espinosa committed
720
721
722
		*error_string = _("log2: domain error");
		return NULL;
	}
723
	return value_float (log (t) / M_LN2);
Arturo Espinosa's avatar
Arturo Espinosa committed
724
725
}

726
static char *help_log10 = {
727
	N_("@FUNCTION=LOG10\n"
728
	   "@SYNTAX=LOG10(x)\n"
729
730

	   "@DESCRIPTION="
731
	   "Computes the base-10 logarithm  of x. "
732
733
734
735
736
737
738
	   "\n"

	   "Performing this function on a string or empty cell returns an error. "
	   "\n"
	   "@SEEALSO=EXP, LOG2, LOG")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
739
static Value *
740
gnumeric_log10 (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
741
742
743
744
{
	float_t t;

	t = value_get_as_double (argv [0]);
745
	if (t <= 0.0){
Arturo Espinosa's avatar
Arturo Espinosa committed
746
747
748
		*error_string = _("log10: domain error");
		return NULL;
	}
749
	return value_float (log10 (t));
Arturo Espinosa's avatar
Arturo Espinosa committed
750
751
}

752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
static char *help_min = {
	N_("@FUNCTION=MIN\n"
	   "@SYNTAX=MIN(b1, b2, ...)\n"

	   "@DESCRIPTION="
	   "MIN returns the value of the element of the values passed "
	   "that has the smallest value. With negative numbers considered "
	   "smaller than positive numbers."
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing."
	   "\n"
	   "@SEEALSO=MAX,ABS")
};

static char *help_max = {
	N_("@FUNCTION=MAX\n"
	   "@SYNTAX=MAX(b1, b2, ...)\n"

	   "@DESCRIPTION="
	   "MAX returns the value of the element of the values passed "
	   "that has the largest value. With negative numbers considered "
	   "smaller than positive numbers."
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing."
	   "\n"
	   "@SEEALSO=MIN,ABS")
};

780
enum {
781
782
	OPER_MIN,
	OPER_MAX
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
};

typedef struct {
	int   operation;
	int   found;
	Value *result;
} min_max_closure_t;

static int
callback_function_min_max (Sheet *sheet, Value *value, char **error_string, void *closure)
{
	min_max_closure_t *mm = closure;
	
	switch (value->type){
	case VALUE_INTEGER:
		if (mm->found){
799
			if (mm->operation == OPER_MIN){
800
801
802
803
804
805
806
807
808
809
810
811
812
813
				if (value->v.v_int < mm->result->v.v_float)
					mm->result->v.v_float = value->v.v_int;
			} else {
				if (value->v.v_int > mm->result->v.v_float)
					mm->result->v.v_float = value->v.v_int;
			}
		} else {
			mm->found = 1;
			mm->result->v.v_float = value->v.v_int;
		}
		break;

	case VALUE_FLOAT:
		if (mm->found){
814
			if (mm->operation == OPER_MIN){
815
816
817
818
819
820
821
822
823
824
825
826
827
				if (value->v.v_float < mm->result->v.v_float)
					mm->result->v.v_float = value->v.v_float;
			} else {
				if (value->v.v_float > mm->result->v.v_float)
					mm->result->v.v_float = value->v.v_float;
			}
		} else {
			mm->found = 1;
			mm->result->v.v_float = value->v.v_float;
		}

	default:
		/* ignore strings */
828
		break;
829
830
831
832
833
834
835
836
837
838
839
	}
	
	return TRUE;
}

static Value *
gnumeric_min (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	min_max_closure_t closure;
	Sheet *sheet = (Sheet *) tsheet;

840
	closure.operation = OPER_MIN;
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
	closure.found  = 0;
	closure.result = g_new (Value, 1);
	closure.result->type = VALUE_FLOAT;
	closure.result->v.v_float = 0;

	function_iterate_argument_values (sheet, callback_function_min_max,
					  &closure, expr_node_list,
					  eval_col, eval_row, error_string);

	return 	closure.result;
}

static Value *
gnumeric_max (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	min_max_closure_t closure;
	Sheet *sheet = (Sheet *) tsheet;

859
	closure.operation = OPER_MAX;
860
861
862
863
864
865
866
867
868
869
870
	closure.found  = 0;
	closure.result = g_new (Value, 1);
	closure.result->type = VALUE_FLOAT;
	closure.result->v.v_float = 0;

	function_iterate_argument_values (sheet, callback_function_min_max,
					  &closure, expr_node_list,
					  eval_col, eval_row, error_string);
	return 	closure.result;
}

871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
static char *help_not = {
	N_("@FUNCTION=NOT\n"
	   "@SYNTAX=NOT(number)\n"

	   "@DESCRIPTION="
	   "Implements the logical NOT function: the result is TRUE if the "
	   "number is zero;  othewise the result is FALSE.\n\n"

	   "@SEEALSO=AND, OR")
};

static Value *
gnumeric_not (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	int b;
	
	b = value_get_as_int (argv [0]);
	
	return value_int (!b);
}

892
893
static char *help_or = {
	N_("@FUNCTION=OR\n"
894
	   "@SYNTAX=OR(b1, b2, ...)\n"
895
896

	   "@DESCRIPTION="
897
	   "Implements the logical OR function: the result is TRUE if any of the "
898
	   "values evaluated to TRUE.\n"
899
900
	   "b1, trough bN are expressions that should evaluate to TRUE or FALSE. "
	   "If an integer or floating point value is provided zero is considered "
901
902
903
904
905
	   "FALSE and anything else is TRUE.\n"
	   "If the values contain strings or empty cells those values are "
	   "ignored.  If no logical values are provided, then the error '#VALUE!'"
	   "is returned.\n"

906
	   "@SEEALSO=AND, NOT")
907
908
};

Arturo Espinosa's avatar
Arturo Espinosa committed
909
910
911
912
913
914
915
static int
callback_function_or (Sheet *sheet, Value *value, char **error_string, void *closure)
{
	Value *result = closure;
	
	switch (value->type){
	case VALUE_INTEGER:
916
		if (value->v.v_int != 0){
Arturo Espinosa's avatar
Arturo Espinosa committed
917
918
919
920
921
922
923
			result->v.v_int = 1;
			return FALSE;
		} else
			result->v.v_int = 0;
		break;

	case VALUE_FLOAT:
924
		if (value->v.v_float != 0.0){
Arturo Espinosa's avatar
Arturo Espinosa committed
925
926
927
928
929
930
931
			result->v.v_int = 1;
			return FALSE;
		} else
			result->v.v_int = 0;

	default:
		/* ignore strings */
932
		break;
Arturo Espinosa's avatar
Arturo Espinosa committed
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
	}
	
	return TRUE;
}

static Value *
gnumeric_or (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *result;
	Sheet *sheet = (Sheet *) tsheet;

	result = g_new (Value, 1);
	result->type = VALUE_INTEGER;
	result->v.v_int = -1;

	function_iterate_argument_values (sheet, callback_function_or,
					  result, expr_node_list,
					  eval_col, eval_row, error_string);

	/* See if there was any value worth using */
	if (result->v.v_int == -1){
		value_release (result);
		*error_string = _("#VALUE");
		return NULL;
	}
	return result;
}

961
962
static char *help_radians = {
	N_("@FUNCTION=RADIANS\n"
963
	   "@SYNTAX=RADIANS(x)\n"
964
965

	   "@DESCRIPTION="
966
967
	   "Computes the number of radians equivalent to  "
	   "x degrees. "
968
969
970
971
972
973
974
	   "\n"

	   "Performing this function on a string or empty cell simply does nothing. "
	   "\n"
	   
	   "@SEEALSO=PI,DEGREES")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
975
976

static Value *
977
gnumeric_radians (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
978
{
979
980
	return value_float ((value_get_as_double (argv [0]) * M_PI) / 180);
}
Arturo Espinosa's avatar
Arturo Espinosa committed
981

982
983
static char *help_sin = {
	N_("@FUNCTION=SIN\n"
984
	   "@SYNTAX=SIN(x)\n"
Arturo Espinosa's avatar
Arturo Espinosa committed
985

986
	   "@DESCRIPTION="
987
	   "The SIN function returns the sine of x, where x is given "
988
989
990
991
992
993
994
           " in radians. "
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=COS, COSH, SINH, TAN, TANH, RADIANS, DEGREES")
};
Arturo Espinosa's avatar
Arturo Espinosa committed
995
996

static Value *
997
gnumeric_sin (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
998
{
999
	return value_float (sin (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
1000
1001
}

1002
1003
static char *help_sinh = {
	N_("@FUNCTION=SINH\n"
1004
	   "@SYNTAX=SINH(x)\n"
1005
1006

	   "@DESCRIPTION="
1007
1008
1009
	   "The SINH  function  returns  the  hyperbolic sine of x, "
	   "which is defined mathematically as (exp(x) - exp(-x)) / 2. "
	   " x is in radians. "
1010
1011
1012
1013
1014
1015
1016
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=SIN, COS, COSH, TAN, TANH, DEGREES, RADIANS, EXP")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
1017
static Value *
1018
gnumeric_sinh (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
1019
{
1020
	return value_float (sinh (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
1021
1022
}

1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
static char *help_sqrt = {
	N_("@FUNCTION=SQRT\n"
	   "@SYNTAX=SQRT(x)\n"

	   "@DESCRIPTION="
	   "The SQRT  function  returns  the  square root of x, "
	   "\n"
	   "If x is negative returns #NUM!."
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=POW")
};

static Value *
gnumeric_sqrt (struct FunctionDefinition *i, Value *argv [], char **error_string)
{
	float_t x = value_get_as_double (argv[0]) ;
	if (x<0) {
		*error_string = _("#NUM!") ;
		return NULL ;
	}
	return value_float (sqrt(x)) ;
}

1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
static char *help_sum = {
	N_("@FUNCTION=SUM\n"
	   "@SYNTAX=SUM(value1, value2, ...)\n"

	   "@DESCRIPTION="
	   "Computes the sum of all the values and cells referenced in the "
	   "argument list. " 
	   "\n"

	   "@SEEALSO=AVERAGE, COUNT")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
1059
1060
1061
1062
1063
1064
1065
static int
callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *closure)
{
	Value *result = (Value *) closure;

	switch (value->type){
	case VALUE_INTEGER:
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
		if (result->type == VALUE_INTEGER){
			if ((result->v.v_int > 0) && (value->v.v_int > 0)){
				int sum = result->v.v_int + value->v.v_int;

				if (sum < result->v.v_int){
					double n = result->v.v_int + value->v.v_int;
					
					result->type = VALUE_FLOAT;
					result->v.v_float = n;
				} else
					result->v.v_int = sum;
			} else if ((result->v.v_int < 0) && (value->v.v_int < 0)){
				int sum = result->v.v_int + value->v.v_int;

				if (sum > result->v.v_int){
					double n = result->v.v_int + value->v.v_int;
					
					result->type = VALUE_FLOAT;
					result->v.v_float = n;
				} else {
					result->v.v_int = sum;
				}
			} else {
				result->v.v_int += value->v.v_int;
			}
		} else
1092
			result->v.v_float += value->v.v_int;
Arturo Espinosa's avatar
Arturo Espinosa committed
1093
1094
1095
		break;
		
	case VALUE_FLOAT:
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
		if (result->type == VALUE_FLOAT)
			result->v.v_float += value->v.v_float;
		else {
			double v = result->v.v_int;

			/* cast to float */
			
			result->type = VALUE_FLOAT;
			result->v.v_float = v + value->v.v_float;
		}
Arturo Espinosa's avatar
Arturo Espinosa committed
1106
		break;
1107
1108
1109

	case VALUE_STRING:
		break;
Arturo Espinosa's avatar
Arturo Espinosa committed
1110
1111
		
	default:
1112
1113
1114
1115
		g_warning ("Unimplemented value->type in callback_function_sum : %s (%d)",
			   (value->type == VALUE_CELLRANGE) ? "CELLRANGE" :
			   (value->type == VALUE_ARRAY) ? "ARRAY" :
			   "UNKOWN!", value->type);
Arturo Espinosa's avatar
Arturo Espinosa committed
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
		break;
	}		
	return TRUE;
}

static Value *
gnumeric_sum (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *result;
	Sheet *sheet = (Sheet *) tsheet;

	result = g_new (Value, 1);
1128
1129
	result->type = VALUE_INTEGER;
	result->v.v_int = 0;
Arturo Espinosa's avatar
Arturo Espinosa committed
1130
1131
1132
1133
1134
1135
1136
	
	function_iterate_argument_values (sheet, callback_function_sum, result, expr_node_list,
					  eval_col, eval_row, error_string);

	return result;
}

1137
1138
static char *help_tan = {
	N_("@FUNCTION=TAN\n"
1139
	   "@SYNTAX=TAN(x)\n"
1140
1141

	   "@DESCRIPTION="
1142
	   "The TAN function  returns the tangent of x, where x is "
1143
1144
1145
1146
1147
1148
1149
1150
	   "given in radians. "
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=TANH, COS, COSH, SIN, SINH, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
1151
static Value *
1152
gnumeric_tan (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
1153
{
1154
	return value_float (tan (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
1155
1156
}

1157
1158
static char *help_tanh = {
	N_("@FUNCTION=TANH\n"
1159
	   "@SYNTAX=TANH(x)\n"
1160
1161

	   "@DESCRIPTION="
1162
1163
	   " The TANH function returns the hyperbolic tangent of x, "
	   " which is defined mathematically as sinh(x) / cosh(x). "
1164
1165
1166
1167
1168
1169
1170
	   "\n"
	   "Performing this function on a string or empty cell simply does nothing. "
	   "This function only takes one argument."
	   "\n"
	   "@SEEALSO=TAN, SIN, SINH, COS, COSH, DEGREES, RADIANS")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
1171
static Value *
1172
gnumeric_tanh (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
1173
{
1174
	return value_float (tanh (value_get_as_double (argv [0])));
Arturo Espinosa's avatar
Arturo Espinosa committed
1175
1176
}

1177
1178
1179
1180
1181
1182
1183
1184
static char *help_pi = {
	N_("@FUNCTION=PI\n"
	   "@SYNTAX=PI()\n"

	   "@DESCRIPTION=The PI functions returns the value of Pi "
	   "as defined by M_PI."
	   "\n"

1185
	   "This function is called with no arguments."
1186
1187
1188
1189
	   "\n"
	   "@SEEALSO=")
};

Arturo Espinosa's avatar
Arturo Espinosa committed
1190
static Value *
1191
gnumeric_pi (struct FunctionDefinition *i, Value *argv [], char **error_string)
Arturo Espinosa's avatar
Arturo Espinosa committed
1192
{
1193
	return value_float (M_PI);
Arturo Espinosa's avatar
Arturo Espinosa committed
1194
1195
}

Arturo Espinosa's avatar
Arturo Espinosa committed
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
static char *help_trunc = {
	N_("@FUNCTION=TRUNC\n"
	   "@SYNTAX=TRUNC(number[,digits])\n"

	   "@DESCRIPTION=The TRUNC function returns the value of number "
	   "truncated to the number of digits specified.  If digits is omited "
	   "then digits defaults to zero."
	   "\n"

	   "\n"
	   "@SEEALSO=")
};
static Value *
gnumeric_trunc (void *tsheet, GList *expr_node_list, int eval_col, int eval_row, char **error_string)
{
	Value *number;
	int args = g_list_length (expr_node_list);
	int decimals = 0;
	double v, integral, fraction;
	
	if (args < 1 || args > 2){
		*error_string = _("Invalid number of arguments");
		return NULL;
	}

	number = eval_expr (tsheet, (ExprTree *) expr_node_list->data, eval_col, eval_row, error_string);
	if (!number)
		return NULL;

	v = number->v.v_float;
	value_release (number);
	
	if (args == 2){
		Value *value;

		value = eval_expr (tsheet, (ExprTree *) expr_node_list->next->data, eval_col, eval_row, error_string);
		if (!value){
			return NULL;
		}
		
		decimals = value_get_as_int (value);
		value_release (value);
	}

	fraction = modf (v, &integral);
	if (decimals){
		double pot = pow (10, decimals);
		
		return value_float (integral + floor (fraction * pot) / pot);
	} else
		return value_float (integral);
}

Arturo Espinosa's avatar
Arturo Espinosa committed
1249
FunctionDefinition math_functions [] = {
1250
1251
1252
1253
1254
1255
1256
1257
1258
	{ "abs",     "f",    "number",    &help_abs,   NULL, gnumeric_abs },
	{ "acos",    "f",    "number",    &help_acos,  NULL, gnumeric_acos },
	{ "acosh",   "f",    "number",    &help_acosh, NULL, gnumeric_acosh },
	{ "and",     0,      "",          &help_and,   gnumeric_and, NULL },
	{ "asin",    "f",    "number",    &help_asin,  NULL, gnumeric_asin },
	{ "asinh",   "f",    "number",    &help_asinh, NULL, gnumeric_asinh },
	{ "atan",    "f",    "number",    &help_atan,  NULL, gnumeric_atan },
	{ "atanh",   "f",    "number",    &help_atanh, NULL, gnumeric_atanh },
	{ "atan2",   "ff",   "xnum,ynum", &help_atan2, NULL, gnumeric_atan2 },
Arturo Espinosa's avatar
Arturo Espinosa committed
1259
1260
	/* avedev */
	{ "average", 0,      "",          &help_average, gnumeric_average, NULL },
1261
1262
1263
1264
1265
1266
1267
	{ "cos",     "f",    "number",    &help_cos,     NULL, gnumeric_cos },
	{ "cosh",    "f",    "number",    &help_cosh,    NULL, gnumeric_cosh },
	{ "count",   0,      "",          &help_count,   gnumeric_count, NULL },
	{ "ceil",    "f",    "number",    &help_ceil,    NULL, gnumeric_ceil },
	{ "degrees", "f",    "number",    &help_degrees, NULL, gnumeric_degrees },
	{ "exp",     "f",    "number",    &help_exp,     NULL, gnumeric_exp },
	{ "fact",    "f",    "number",    &help_fact,    NULL, gnumeric_fact },
Jukka-Pekka Iivonen's avatar
Jukka-Pekka Iivonen committed
1268
	{ "combin",  "ff",   "n,k",       &help_combin,  NULL, gnumeric_combin },
1269
1270
1271
1272
1273
1274
1275
	{ "floor",   "f",    "number",    &help_floor,   NULL, gnumeric_floor },
	{ "int",     "f",    "number",    &help_int,     NULL, gnumeric_int },
	{ "log",     "f",    "number",    &help_log,     NULL, gnumeric_log },
	{ "log2",    "f",    "number",    &help_log2,    NULL, gnumeric_log2 },
	{ "log10",   "f",    "number",    &help_log10,   NULL, gnumeric_log10 },
	{ "min",     0,      "",          &help_min,     gnumeric_min, NULL },
	{ "max",     0,      "",          &help_max,     gnumeric_max, NULL },
1276
	{ "not",     "f",    "number",    &help_not,     NULL, gnumeric_not },
1277
	{ "or",      0,      "",          &help_or,      gnumeric_or, NULL },
1278
	{ "power",   "ff",   "x,y",       &help_power,   NULL, gnumeric_power },
1279
1280
1281
	{ "radians", "f",    "number",    &help_radians, NULL, gnumeric_radians },
	{ "sin",     "f",    "number",    &help_sin,     NULL, gnumeric_sin },
	{ "sinh",    "f",    "number",    &help_sinh,    NULL, gnumeric_sinh },
1282
	{ "sqrt",    "f",    "number",    &help_sqrt,    NULL, gnumeric_sqrt },
1283
1284
1285
	{ "sum",     0,      "number",    &help_sum,     gnumeric_sum, NULL },
	{ "tan",     "f",    "number",    &help_tan,     NULL, gnumeric_tan },
	{ "tanh",    "f",    "number",    &help_tanh,    NULL, gnumeric_tanh },
Arturo Espinosa's avatar
Arturo Espinosa committed
1286
1287
	{ "trunc",   "f",    "number",    &help_trunc,   gnumeric_trunc, NULL },
	{ "pi",      "",     "",          &help_pi,      NULL, gnumeric_pi },
Arturo Espinosa's avatar
Arturo Espinosa committed
1288
1289
1290
	{ NULL, NULL },
};

1291