[FFmpeg-devel] [PATCH] eval: add mathematical constants (PI, E, PHI).
Nicolas George
nicolas.george at normalesup.org
Thu Oct 13 13:24:24 CEST 2011
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
doc/eval.texi | 10 ++++++++++
libavutil/eval.c | 18 ++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)
If this is accepted, I can submit patches to remove them from the various
places where they are implemented as variables.
diff --git a/doc/eval.texi b/doc/eval.texi
index b41f31e..18d8487 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -99,6 +99,16 @@ Return the greatest common divisor of @var{x} and @var{y}. If both @var{x} and
@var{y} are 0 or either or both are less than zero then behavior is undefined.
@end table
+The following constants are available:
+ at table @option
+ at item PI
+area of the unit disc, approximatively 3.14
+ at item E
+exp(1) (Euler's number), approximatively 2.718
+ at item PHI
+golden ratio (1+sqrt(5))/2, approximatively 1.618
+ at end table
+
Note that:
@code{*} works like AND
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 0c61ad0..3a8b60d 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -72,6 +72,15 @@ static const int8_t si_prefixes['z' - 'E' + 1] = {
['Y'-'E']= 24,
};
+static const struct {
+ const char *name;
+ double value;
+} constants[] = {
+ { "E", M_E },
+ { "PI", M_PI },
+ { "PHI", M_PHI },
+};
+
double av_strtod(const char *numstr, char **tail)
{
double d;
@@ -233,6 +242,15 @@ static int parse_primary(AVExpr **e, Parser *p)
return 0;
}
}
+ for (i = 0; i < FF_ARRAY_ELEMS(constants); i++) {
+ if (strmatch(p->s, constants[i].name)) {
+ p->s += strlen(constants[i].name);
+ d->type = e_value;
+ d->value = constants[i].value;
+ *e = d;
+ return 0;
+ }
+ }
p->s= strchr(p->s, '(');
if (p->s==NULL) {
--
1.7.6.3
More information about the ffmpeg-devel
mailing list