Commit 4b6b00d2 authored by Arturo Espinosa's avatar Arturo Espinosa
Browse files

a function here, a function there before sleeping

parent c9a4971e
/*
* func.c: Built in mathematical functions and functions registration
* fn-math.c: Built in mathematical functions and functions registration
* (C) 1998 The Free Software Foundation
*
* Author:
......@@ -279,13 +279,12 @@ gnumeric_bin2dec (Value *argv [], char **error_string)
case VALUE_STRING:
p = argv [0]->v.str->str;
while (*p){
for (;*p; p++){
if (!(*p == '0' || *p == '1')){
*error_string = "#NUM!";
return NULL;
}
/* FIXME: implement */
result = *p;
result = result << 1 | (*p - '0');
}
break;
......@@ -380,6 +379,46 @@ gnumeric_exp (Value *argv [], char **error_string)
return v;
}
static float_t
fact (int n)
{
if (n == 0)
return 1;
return (n * fact (n - 1));
}
static Value *
gnumeric_fact (Value *argv [], char **error_string)
{
Value *res;
int i;
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);
if (i > 69){
i = 69;
}
res->type = VALUE_FLOAT;
res->v.v_float = fact (i);
return res;
}
static Value *
gnumeric_floor (Value *argv [], char **error_string)
{
......@@ -749,6 +788,7 @@ FunctionDefinition math_functions [] = {
{ "ceil", "f", "number", NULL, NULL, gnumeric_ceil },
{ "degrees", "f", "number", NULL, NULL, gnumeric_degrees },
{ "exp", "f", "number", NULL, NULL, gnumeric_exp },
{ "fact", "f", "number", NULL, NULL, gnumeric_fact },
{ "floor", "f", "number", NULL, NULL, gnumeric_floor },
{ "int", "f", "number", NULL, NULL, gnumeric_int },
{ "log", "f", "number", NULL, NULL, gnumeric_log },
......
......@@ -24,6 +24,7 @@ GNUMERIC_BASE_SOURCES = \
func.h \
fn-sheet.c \
fn-math.c \
fn-misc.c \
gnumeric-sheet.c \
gnumeric-sheet.h \
gnumeric-util.c \
......
/*
* func.c: Built in mathematical functions and functions registration
* fn-math.c: Built in mathematical functions and functions registration
* (C) 1998 The Free Software Foundation
*
* Author:
......@@ -279,13 +279,12 @@ gnumeric_bin2dec (Value *argv [], char **error_string)
case VALUE_STRING:
p = argv [0]->v.str->str;
while (*p){
for (;*p; p++){
if (!(*p == '0' || *p == '1')){
*error_string = "#NUM!";
return NULL;
}
/* FIXME: implement */
result = *p;
result = result << 1 | (*p - '0');
}
break;
......@@ -380,6 +379,46 @@ gnumeric_exp (Value *argv [], char **error_string)
return v;
}
static float_t
fact (int n)
{
if (n == 0)
return 1;
return (n * fact (n - 1));
}
static Value *
gnumeric_fact (Value *argv [], char **error_string)
{
Value *res;
int i;
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);
if (i > 69){
i = 69;
}
res->type = VALUE_FLOAT;
res->v.v_float = fact (i);
return res;
}
static Value *
gnumeric_floor (Value *argv [], char **error_string)
{
......@@ -749,6 +788,7 @@ FunctionDefinition math_functions [] = {
{ "ceil", "f", "number", NULL, NULL, gnumeric_ceil },
{ "degrees", "f", "number", NULL, NULL, gnumeric_degrees },
{ "exp", "f", "number", NULL, NULL, gnumeric_exp },
{ "fact", "f", "number", NULL, NULL, gnumeric_fact },
{ "floor", "f", "number", NULL, NULL, gnumeric_floor },
{ "int", "f", "number", NULL, NULL, gnumeric_int },
{ "log", "f", "number", NULL, NULL, gnumeric_log },
......
/*
* func.c: Built in sheet functions
* fn-sheet.c: Built in sheet functions
* (C) 1998 The Free Software Foundation
*
* Author:
......
......@@ -149,6 +149,7 @@ functions_init (void)
{
install_symbols (math_functions);
install_symbols (sheet_functions);
install_symbols (misc_functions);
}
void
......
......@@ -3,6 +3,7 @@
extern FunctionDefinition math_functions [];
extern FunctionDefinition sheet_functions [];
extern FunctionDefinition misc_functions [];
typedef int (*FunctionIterateCallback)(Sheet *sheet, Value *value, char **error_string, void *);
......
/*
* func.c: Built in mathematical functions and functions registration
* fn-math.c: Built in mathematical functions and functions registration
* (C) 1998 The Free Software Foundation
*
* Author:
......@@ -279,13 +279,12 @@ gnumeric_bin2dec (Value *argv [], char **error_string)
case VALUE_STRING:
p = argv [0]->v.str->str;
while (*p){
for (;*p; p++){
if (!(*p == '0' || *p == '1')){
*error_string = "#NUM!";
return NULL;
}
/* FIXME: implement */
result = *p;
result = result << 1 | (*p - '0');
}
break;
......@@ -380,6 +379,46 @@ gnumeric_exp (Value *argv [], char **error_string)
return v;
}
static float_t
fact (int n)
{
if (n == 0)
return 1;
return (n * fact (n - 1));
}
static Value *
gnumeric_fact (Value *argv [], char **error_string)
{
Value *res;
int i;
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);
if (i > 69){
i = 69;
}
res->type = VALUE_FLOAT;
res->v.v_float = fact (i);
return res;
}
static Value *
gnumeric_floor (Value *argv [], char **error_string)
{
......@@ -749,6 +788,7 @@ FunctionDefinition math_functions [] = {
{ "ceil", "f", "number", NULL, NULL, gnumeric_ceil },
{ "degrees", "f", "number", NULL, NULL, gnumeric_degrees },
{ "exp", "f", "number", NULL, NULL, gnumeric_exp },
{ "fact", "f", "number", NULL, NULL, gnumeric_fact },
{ "floor", "f", "number", NULL, NULL, gnumeric_floor },
{ "int", "f", "number", NULL, NULL, gnumeric_int },
{ "log", "f", "number", NULL, NULL, gnumeric_log },
......
/*
* func.c: Built in sheet functions
* fn-sheet.c: Built in sheet functions
* (C) 1998 The Free Software Foundation
*
* Author:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment