Commit 940ac911 authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Added ROUND().

1999-05-04  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/fn-math: Added ROUND().

	* src/fn-information: Added new file for information functions.
	New function COUNTBLANK() implemented.

	* src/Makefile.am, src/func.[ch]: Added `fn-information.c'.
parent ccbf6a01
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math: Added ROUND().
* src/fn-information: Added new file for information functions.
New function COUNTBLANK() implemented.
* src/Makefile.am, src/func.[ch]: Added `fn-information.c'.
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-database.c: Added DCOUNTA().
......
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math: Added ROUND().
* src/fn-information: Added new file for information functions.
New function COUNTBLANK() implemented.
* src/Makefile.am, src/func.[ch]: Added `fn-information.c'.
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-database.c: Added DCOUNTA().
......
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math: Added ROUND().
* src/fn-information: Added new file for information functions.
New function COUNTBLANK() implemented.
* src/Makefile.am, src/func.[ch]: Added `fn-information.c'.
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-database.c: Added DCOUNTA().
......
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math: Added ROUND().
* src/fn-information: Added new file for information functions.
New function COUNTBLANK() implemented.
* src/Makefile.am, src/func.[ch]: Added `fn-information.c'.
1999-05-04 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-database.c: Added DCOUNTA().
......
/*
* fn-information.c: Information built-in functions
*
* Author:
* Jukka-Pekka Iivonen (iivonen@iki.fi)
*
*/
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"
static char *help_countblank = {
N_("@FUNCTION=COUNTBLANK\n"
"@SYNTAX=COUNTBLANK(range)\n"
"@DESCRIPTION="
"COUNTBLANK returns the number of blank cells in a range. "
"\n"
"@SEEALSO=COUNT")
};
static Value *
gnumeric_countblank (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
Sheet *sheet;
Value *range;
int col_a, col_b, row_a, row_b;
int i, j;
int count;
range = argv[0];
sheet = (Sheet *) range->v.cell_range.cell_a.sheet;
col_a = range->v.cell_range.cell_a.col;
col_b = range->v.cell_range.cell_b.col;
row_a = range->v.cell_range.cell_a.row;
row_b = range->v.cell_range.cell_b.row;
count = 0;
for (i=col_a; i<=col_b; i++)
for (j=row_a; j<=row_b; j++) {
Cell *cell = sheet_cell_get(sheet, i, j);
if (cell == NULL || cell->value == NULL)
count++;
}
return value_int (count);
}
FunctionDefinition information_functions [] = {
{ "countblank", "r", "range", &help_countblank,
NULL, gnumeric_countblank },
{ NULL, NULL }
};
......@@ -1432,6 +1432,53 @@ gnumeric_rounddown (struct FunctionDefinition *i,
}
}
static char *help_round = {
N_("@FUNCTION=ROUND\n"
"@SYNTAX=ROUND(number[,digits])\n"
"@DESCRIPTION="
"ROUND function rounds a given number. "
"@number is the number you want rounded and @digits is the "
"number of digits to which you want to round that number. "
"\n"
"If digits is greater than zero, number is rounded to the "
"given number of digits. "
"If digits is zero or omitted, number is rounded to the "
"nearest integer. "
"If digits is less than zero, number is rounded to the left "
"of the decimal point. "
"\n"
"@SEEALSO=ROUNDDOWN,ROUNDUP")
};
static Value *
gnumeric_round (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
float_t number;
int digits, k, n;
number = value_get_as_double (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
if (digits > 0) {
k=1;
for (n=0; n<digits; n++)
k *= 10;
return value_float ( rint(number * k) / k);
} else if (digits == 0) {
return value_int ((int) number);
} else {
k=1;
for (n=0; n<-digits; n++)
k *= 10;
return value_float (rint(number / k) * k);
}
}
static char *help_roundup = {
N_("@FUNCTION=ROUNDUP\n"
"@SYNTAX=ROUNDUP(number[,digits])\n"
......@@ -1843,6 +1890,7 @@ FunctionDefinition math_functions [] = {
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "rand", "", "", &help_rand, NULL, gnumeric_rand },
{ "randbetween", "ff", "bottom,top", &help_randbetween, NULL, gnumeric_randbetween },
{ "round", "f|f", "number[,digits]", &help_round, NULL, gnumeric_round },
{ "rounddown", "f|f", "number,digits", &help_rounddown, NULL, gnumeric_rounddown },
{ "roundup", "f|f", "number,digits", &help_roundup, NULL, gnumeric_roundup },
{ "sign", "f", "number", &help_sign, NULL, gnumeric_sign },
......
......@@ -76,6 +76,7 @@ GNUMERIC_BASE_SOURCES = \
fn-date.c \
fn-eng.c \
fn-financial.c \
fn-information.c \
fn-logical.c \
fn-lookup.c \
fn-math.c \
......
/*
* fn-information.c: Information built-in functions
*
* Author:
* Jukka-Pekka Iivonen (iivonen@iki.fi)
*
*/
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"
static char *help_countblank = {
N_("@FUNCTION=COUNTBLANK\n"
"@SYNTAX=COUNTBLANK(range)\n"
"@DESCRIPTION="
"COUNTBLANK returns the number of blank cells in a range. "
"\n"
"@SEEALSO=COUNT")
};
static Value *
gnumeric_countblank (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
Sheet *sheet;
Value *range;
int col_a, col_b, row_a, row_b;
int i, j;
int count;
range = argv[0];
sheet = (Sheet *) range->v.cell_range.cell_a.sheet;
col_a = range->v.cell_range.cell_a.col;
col_b = range->v.cell_range.cell_b.col;
row_a = range->v.cell_range.cell_a.row;
row_b = range->v.cell_range.cell_b.row;
count = 0;
for (i=col_a; i<=col_b; i++)
for (j=row_a; j<=row_b; j++) {
Cell *cell = sheet_cell_get(sheet, i, j);
if (cell == NULL || cell->value == NULL)
count++;
}
return value_int (count);
}
FunctionDefinition information_functions [] = {
{ "countblank", "r", "range", &help_countblank,
NULL, gnumeric_countblank },
{ NULL, NULL }
};
......@@ -1432,6 +1432,53 @@ gnumeric_rounddown (struct FunctionDefinition *i,
}
}
static char *help_round = {
N_("@FUNCTION=ROUND\n"
"@SYNTAX=ROUND(number[,digits])\n"
"@DESCRIPTION="
"ROUND function rounds a given number. "
"@number is the number you want rounded and @digits is the "
"number of digits to which you want to round that number. "
"\n"
"If digits is greater than zero, number is rounded to the "
"given number of digits. "
"If digits is zero or omitted, number is rounded to the "
"nearest integer. "
"If digits is less than zero, number is rounded to the left "
"of the decimal point. "
"\n"
"@SEEALSO=ROUNDDOWN,ROUNDUP")
};
static Value *
gnumeric_round (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
float_t number;
int digits, k, n;
number = value_get_as_double (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
if (digits > 0) {
k=1;
for (n=0; n<digits; n++)
k *= 10;
return value_float ( rint(number * k) / k);
} else if (digits == 0) {
return value_int ((int) number);
} else {
k=1;
for (n=0; n<-digits; n++)
k *= 10;
return value_float (rint(number / k) * k);
}
}
static char *help_roundup = {
N_("@FUNCTION=ROUNDUP\n"
"@SYNTAX=ROUNDUP(number[,digits])\n"
......@@ -1843,6 +1890,7 @@ FunctionDefinition math_functions [] = {
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "rand", "", "", &help_rand, NULL, gnumeric_rand },
{ "randbetween", "ff", "bottom,top", &help_randbetween, NULL, gnumeric_randbetween },
{ "round", "f|f", "number[,digits]", &help_round, NULL, gnumeric_round },
{ "rounddown", "f|f", "number,digits", &help_rounddown, NULL, gnumeric_rounddown },
{ "roundup", "f|f", "number,digits", &help_roundup, NULL, gnumeric_roundup },
{ "sign", "f", "number", &help_sign, NULL, gnumeric_sign },
......
......@@ -272,6 +272,7 @@ functions_init (void)
install_symbols (lookup_functions, _("Data / Lookup"));
install_symbols (logical_functions, _("Logical"));
install_symbols (database_functions, _("Database"));
install_symbols (information_functions, _("Information"));
}
void
......
......@@ -15,6 +15,7 @@ extern FunctionDefinition eng_functions [];
extern FunctionDefinition lookup_functions [];
extern FunctionDefinition logical_functions [];
extern FunctionDefinition database_functions [];
extern FunctionDefinition information_functions [];
typedef int (*FunctionIterateCallback)(Sheet *sheet, Value *value, char **error_string, void *);
......
/*
* fn-information.c: Information built-in functions
*
* Author:
* Jukka-Pekka Iivonen (iivonen@iki.fi)
*
*/
#include <config.h>
#include <gnome.h>
#include <ctype.h>
#include "math.h"
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "utils.h"
#include "func.h"
static char *help_countblank = {
N_("@FUNCTION=COUNTBLANK\n"
"@SYNTAX=COUNTBLANK(range)\n"
"@DESCRIPTION="
"COUNTBLANK returns the number of blank cells in a range. "
"\n"
"@SEEALSO=COUNT")
};
static Value *
gnumeric_countblank (struct FunctionDefinition *n,
Value *argv [], char **error_string)
{
Sheet *sheet;
Value *range;
int col_a, col_b, row_a, row_b;
int i, j;
int count;
range = argv[0];
sheet = (Sheet *) range->v.cell_range.cell_a.sheet;
col_a = range->v.cell_range.cell_a.col;
col_b = range->v.cell_range.cell_b.col;
row_a = range->v.cell_range.cell_a.row;
row_b = range->v.cell_range.cell_b.row;
count = 0;
for (i=col_a; i<=col_b; i++)
for (j=row_a; j<=row_b; j++) {
Cell *cell = sheet_cell_get(sheet, i, j);
if (cell == NULL || cell->value == NULL)
count++;
}
return value_int (count);
}
FunctionDefinition information_functions [] = {
{ "countblank", "r", "range", &help_countblank,
NULL, gnumeric_countblank },
{ NULL, NULL }
};
......@@ -1432,6 +1432,53 @@ gnumeric_rounddown (struct FunctionDefinition *i,
}
}
static char *help_round = {
N_("@FUNCTION=ROUND\n"
"@SYNTAX=ROUND(number[,digits])\n"
"@DESCRIPTION="
"ROUND function rounds a given number. "
"@number is the number you want rounded and @digits is the "
"number of digits to which you want to round that number. "
"\n"
"If digits is greater than zero, number is rounded to the "
"given number of digits. "
"If digits is zero or omitted, number is rounded to the "
"nearest integer. "
"If digits is less than zero, number is rounded to the left "
"of the decimal point. "
"\n"
"@SEEALSO=ROUNDDOWN,ROUNDUP")
};
static Value *
gnumeric_round (struct FunctionDefinition *i,
Value *argv [], char **error_string)
{
float_t number;
int digits, k, n;
number = value_get_as_double (argv[0]);
if (argv[1] == NULL)
digits = 0;
else
digits = value_get_as_int (argv[1]);
if (digits > 0) {
k=1;
for (n=0; n<digits; n++)
k *= 10;
return value_float ( rint(number * k) / k);
} else if (digits == 0) {
return value_int ((int) number);
} else {
k=1;
for (n=0; n<-digits; n++)
k *= 10;
return value_float (rint(number / k) * k);
}
}
static char *help_roundup = {
N_("@FUNCTION=ROUNDUP\n"
"@SYNTAX=ROUNDUP(number[,digits])\n"
......@@ -1843,6 +1890,7 @@ FunctionDefinition math_functions [] = {
{ "radians", "f", "number", &help_radians, NULL, gnumeric_radians },
{ "rand", "", "", &help_rand, NULL, gnumeric_rand },
{ "randbetween", "ff", "bottom,top", &help_randbetween, NULL, gnumeric_randbetween },
{ "round", "f|f", "number[,digits]", &help_round, NULL, gnumeric_round },
{ "rounddown", "f|f", "number,digits", &help_rounddown, NULL, gnumeric_rounddown },
{ "roundup", "f|f", "number,digits", &help_roundup, NULL, gnumeric_roundup },
{ "sign", "f", "number", &help_sign, NULL, gnumeric_sign },
......
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