Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
gnumeric
Commits
d838fc55
Commit
d838fc55
authored
May 13, 1999
by
Jukka-Pekka Iivonen
Committed by
jpekka
May 13, 1999
Browse files
Added GCD().
1999-05-13 Jukka-Pekka Iivonen <iivonen@iki.fi> * src/fn-math.c: Added GCD().
parent
5e4dd6b1
Changes
7
Hide whitespace changes
Inline
Side-by-side
ChangeLog-1999-07-09
View file @
d838fc55
1999-05-13 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math.c: Added GCD().
1999-05-12 Michael Meeks <michael@imaginator.com>
* src/workbook.c (workbook_setup_edit_area): Added dependancy
...
...
ChangeLog-2000-02-23
View file @
d838fc55
1999-05-13 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math.c: Added GCD().
1999-05-12 Michael Meeks <michael@imaginator.com>
* src/workbook.c (workbook_setup_edit_area): Added dependancy
...
...
OChangeLog-1999-07-09
View file @
d838fc55
1999-05-13 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math.c: Added GCD().
1999-05-12 Michael Meeks <michael@imaginator.com>
* src/workbook.c (workbook_setup_edit_area): Added dependancy
...
...
OChangeLog-2000-02-23
View file @
d838fc55
1999-05-13 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/fn-math.c: Added GCD().
1999-05-12 Michael Meeks <michael@imaginator.com>
* src/workbook.c (workbook_setup_edit_area): Added dependancy
...
...
plugins/fn-math/functions.c
View file @
d838fc55
...
...
@@ -36,6 +36,33 @@ static char *help_ = {
#endif
static
int
gcd
(
int
a
,
int
b
)
{
int
ri
,
ri_1
,
ri_2
,
qi
;
if
(
b
==
0
)
return
a
;
qi
=
a
/
b
;
ri_2
=
a
-
qi
*
b
;
if
(
ri_2
==
0
)
return
1
;
qi
=
b
/
ri_2
;
ri
=
ri_1
=
b
-
qi
*
ri_2
;
while
(
ri
>
0
)
{
qi
=
ri_2
/
ri_1
;
ri
=
ri_2
-
qi
*
ri_1
;
ri_2
=
ri_1
;
ri_1
=
ri
;
}
return
ri_2
;
}
typedef
struct
{
GSList
*
list
;
...
...
@@ -115,6 +142,36 @@ callback_function_criteria (Sheet *sheet, int col, int row,
return
TRUE
;
}
static
char
*
help_gcd
=
{
N_
(
"@FUNCTION=GCD
\n
"
"@SYNTAX=GCD(a,b)
\n
"
"@DESCRIPTION="
"GCD returns the greatest common divisor of to numbers. "
"
\n
"
"If any of the arguments is less than zero, GCD returns #NUM! "
"error. "
"
\n
"
"@SEEALSO=LCM"
)
};
static
Value
*
gnumeric_gcd
(
struct
FunctionDefinition
*
i
,
Value
*
argv
[],
char
**
error_string
)
{
float_t
a
,
b
;
a
=
value_get_as_double
(
argv
[
0
]);
b
=
value_get_as_double
(
argv
[
1
]);
if
(
a
<
0
||
b
<
0
)
{
*
error_string
=
_
(
"#NUM!"
);
return
NULL
;
}
return
value_int
(
gcd
(
a
,
b
));
}
static
char
*
help_abs
=
{
N_
(
"@FUNCTION=ABS
\n
"
"@SYNTAX=ABS(b1)
\n
"
...
...
@@ -2220,6 +2277,8 @@ FunctionDefinition math_functions [] = {
NULL
,
gnumeric_combin
},
{
"floor"
,
"f"
,
"number"
,
&
help_floor
,
NULL
,
gnumeric_floor
},
{
"gcd"
,
"ff"
,
"number1,number2"
,
&
help_gcd
,
NULL
,
gnumeric_gcd
},
{
"int"
,
"f"
,
"number"
,
&
help_int
,
NULL
,
gnumeric_int
},
{
"ln"
,
"f"
,
"number"
,
&
help_ln
,
NULL
,
gnumeric_ln
},
{
"log"
,
"f|f"
,
"number[,base]"
,
&
help_log
,
NULL
,
gnumeric_log
},
...
...
src/fn-math.c
View file @
d838fc55
...
...
@@ -36,6 +36,33 @@ static char *help_ = {
#endif
static
int
gcd
(
int
a
,
int
b
)
{
int
ri
,
ri_1
,
ri_2
,
qi
;
if
(
b
==
0
)
return
a
;
qi
=
a
/
b
;
ri_2
=
a
-
qi
*
b
;
if
(
ri_2
==
0
)
return
1
;
qi
=
b
/
ri_2
;
ri
=
ri_1
=
b
-
qi
*
ri_2
;
while
(
ri
>
0
)
{
qi
=
ri_2
/
ri_1
;
ri
=
ri_2
-
qi
*
ri_1
;
ri_2
=
ri_1
;
ri_1
=
ri
;
}
return
ri_2
;
}
typedef
struct
{
GSList
*
list
;
...
...
@@ -115,6 +142,36 @@ callback_function_criteria (Sheet *sheet, int col, int row,
return
TRUE
;
}
static
char
*
help_gcd
=
{
N_
(
"@FUNCTION=GCD
\n
"
"@SYNTAX=GCD(a,b)
\n
"
"@DESCRIPTION="
"GCD returns the greatest common divisor of to numbers. "
"
\n
"
"If any of the arguments is less than zero, GCD returns #NUM! "
"error. "
"
\n
"
"@SEEALSO=LCM"
)
};
static
Value
*
gnumeric_gcd
(
struct
FunctionDefinition
*
i
,
Value
*
argv
[],
char
**
error_string
)
{
float_t
a
,
b
;
a
=
value_get_as_double
(
argv
[
0
]);
b
=
value_get_as_double
(
argv
[
1
]);
if
(
a
<
0
||
b
<
0
)
{
*
error_string
=
_
(
"#NUM!"
);
return
NULL
;
}
return
value_int
(
gcd
(
a
,
b
));
}
static
char
*
help_abs
=
{
N_
(
"@FUNCTION=ABS
\n
"
"@SYNTAX=ABS(b1)
\n
"
...
...
@@ -2220,6 +2277,8 @@ FunctionDefinition math_functions [] = {
NULL
,
gnumeric_combin
},
{
"floor"
,
"f"
,
"number"
,
&
help_floor
,
NULL
,
gnumeric_floor
},
{
"gcd"
,
"ff"
,
"number1,number2"
,
&
help_gcd
,
NULL
,
gnumeric_gcd
},
{
"int"
,
"f"
,
"number"
,
&
help_int
,
NULL
,
gnumeric_int
},
{
"ln"
,
"f"
,
"number"
,
&
help_ln
,
NULL
,
gnumeric_ln
},
{
"log"
,
"f|f"
,
"number[,base]"
,
&
help_log
,
NULL
,
gnumeric_log
},
...
...
src/functions/fn-math.c
View file @
d838fc55
...
...
@@ -36,6 +36,33 @@ static char *help_ = {
#endif
static
int
gcd
(
int
a
,
int
b
)
{
int
ri
,
ri_1
,
ri_2
,
qi
;
if
(
b
==
0
)
return
a
;
qi
=
a
/
b
;
ri_2
=
a
-
qi
*
b
;
if
(
ri_2
==
0
)
return
1
;
qi
=
b
/
ri_2
;
ri
=
ri_1
=
b
-
qi
*
ri_2
;
while
(
ri
>
0
)
{
qi
=
ri_2
/
ri_1
;
ri
=
ri_2
-
qi
*
ri_1
;
ri_2
=
ri_1
;
ri_1
=
ri
;
}
return
ri_2
;
}
typedef
struct
{
GSList
*
list
;
...
...
@@ -115,6 +142,36 @@ callback_function_criteria (Sheet *sheet, int col, int row,
return
TRUE
;
}
static
char
*
help_gcd
=
{
N_
(
"@FUNCTION=GCD
\n
"
"@SYNTAX=GCD(a,b)
\n
"
"@DESCRIPTION="
"GCD returns the greatest common divisor of to numbers. "
"
\n
"
"If any of the arguments is less than zero, GCD returns #NUM! "
"error. "
"
\n
"
"@SEEALSO=LCM"
)
};
static
Value
*
gnumeric_gcd
(
struct
FunctionDefinition
*
i
,
Value
*
argv
[],
char
**
error_string
)
{
float_t
a
,
b
;
a
=
value_get_as_double
(
argv
[
0
]);
b
=
value_get_as_double
(
argv
[
1
]);
if
(
a
<
0
||
b
<
0
)
{
*
error_string
=
_
(
"#NUM!"
);
return
NULL
;
}
return
value_int
(
gcd
(
a
,
b
));
}
static
char
*
help_abs
=
{
N_
(
"@FUNCTION=ABS
\n
"
"@SYNTAX=ABS(b1)
\n
"
...
...
@@ -2220,6 +2277,8 @@ FunctionDefinition math_functions [] = {
NULL
,
gnumeric_combin
},
{
"floor"
,
"f"
,
"number"
,
&
help_floor
,
NULL
,
gnumeric_floor
},
{
"gcd"
,
"ff"
,
"number1,number2"
,
&
help_gcd
,
NULL
,
gnumeric_gcd
},
{
"int"
,
"f"
,
"number"
,
&
help_int
,
NULL
,
gnumeric_int
},
{
"ln"
,
"f"
,
"number"
,
&
help_ln
,
NULL
,
gnumeric_ln
},
{
"log"
,
"f|f"
,
"number[,base]"
,
&
help_log
,
NULL
,
gnumeric_log
},
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment