aboutsummaryrefslogtreecommitdiff
path: root/src/tests/formula.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-20 07:03:31 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-20 07:03:31 +0000
commit40360b48f4d9ea82200528411a0ed62d2c0e10bb (patch)
tree0ec8ff2920108a833a72d674e081da0c575e9248 /src/tests/formula.cpp
parent2563702e7fa631efbd8f135309817c9d91bec728 (diff)
downloadlibbu++-40360b48f4d9ea82200528411a0ed62d2c0e10bb.tar.gz
libbu++-40360b48f4d9ea82200528411a0ed62d2c0e10bb.tar.bz2
libbu++-40360b48f4d9ea82200528411a0ed62d2c0e10bb.tar.xz
libbu++-40360b48f4d9ea82200528411a0ed62d2c0e10bb.zip
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.
Diffstat (limited to 'src/tests/formula.cpp')
-rw-r--r--src/tests/formula.cpp14
1 files changed, 13 insertions, 1 deletions
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 @@
6 */ 6 */
7 7
8#include "bu/formula.h" 8#include "bu/formula.h"
9#include <math.h>
9 10
10int main( int argc, char *argv[] ) 11int main( int argc, char *argv[] )
11{ 12{
@@ -17,7 +18,18 @@ int main( int argc, char *argv[] )
17 Bu::Formula<uint32_t> uForm; 18 Bu::Formula<uint32_t> uForm;
18 Bu::Formula<double> dForm; 19 Bu::Formula<double> dForm;
19 20
20 printf("u: %s = %u\n", argv[1], uForm.run( argv[1] ) ); 21 class CeilFunc : public Bu::Formula<double>::Func
22 {
23 public:
24 virtual double operator()( double x )
25 {
26 return ceil( x );
27 }
28 };
29
30 dForm.hFunc.insert( "ceil", new CeilFunc() );
31
32// printf("u: %s = %u\n", argv[1], uForm.run( argv[1] ) );
21 printf("d: %s = %f\n", argv[1], dForm.run( argv[1] ) ); 33 printf("d: %s = %f\n", argv[1], dForm.run( argv[1] ) );
22 34
23 return 0; 35 return 0;