From 40360b48f4d9ea82200528411a0ed62d2c0e10bb Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 20 Jan 2009 07:03:31 +0000 Subject: Awesome changes to the formula class! It actually does proper reduction for unary operators now, such as negate and not, and it now handles functions. Functions are actually implemented as unary operators at the moment, so they'll only act on a single value, no commas :-P, but it would probably be pretty easy to make it work on longer call lists. Although I do think that this will work for pretty much all cases out there. --- src/tests/formula.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/tests/formula.cpp') diff --git a/src/tests/formula.cpp b/src/tests/formula.cpp index 429c306..b3b0d5c 100644 --- a/src/tests/formula.cpp +++ b/src/tests/formula.cpp @@ -6,6 +6,7 @@ */ #include "bu/formula.h" +#include int main( int argc, char *argv[] ) { @@ -17,7 +18,18 @@ int main( int argc, char *argv[] ) Bu::Formula uForm; Bu::Formula dForm; - printf("u: %s = %u\n", argv[1], uForm.run( argv[1] ) ); + class CeilFunc : public Bu::Formula::Func + { + public: + virtual double operator()( double x ) + { + return ceil( x ); + } + }; + + dForm.hFunc.insert( "ceil", new CeilFunc() ); + +// printf("u: %s = %u\n", argv[1], uForm.run( argv[1] ) ); printf("d: %s = %f\n", argv[1], dForm.run( argv[1] ) ); return 0; -- cgit v1.2.3