blob: a90ddaf0479b405736e193067c8a7cc8e03d2a96 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
/*
* Copyright (C) 2007-2011 Xagasoft, All rights reserved.
*
* This file is part of the libbu++ library and is released under the
* terms of the license contained in the file LICENSE.
*/
#include "bu/formula.h"
#include <math.h>
int main( int argc, char *argv[] )
{
if( argc < 2 )
{
printf("usage: %s <formula>\n", argv[0] );
return -1;
}
Bu::Formula<uint32_t> uForm;
Bu::Formula<double> dForm;
class DblCeilFunc : public Bu::Formula<double>::Func
{
public:
virtual double operator()( double x )
{
return ceil( x );
}
};
dForm.hFunc.insert( "ceil", new DblCeilFunc() );
class IntCeilFunc : public Bu::Formula<uint32_t>::Func
{
public:
virtual uint32_t operator()( uint32_t x )
{
return x;
}
};
uForm.hFunc.insert( "ceil", new IntCeilFunc() );
uForm.hVars.insert("x", 10 );
dForm.hVars.insert("x", 10.00 );
uForm.hVars.insert("y", 10 );
dForm.hVars.insert("y", 10.00 );
for( int j = 1; j < argc; j++ )
{
printf("u: %s = %u\n", argv[j], uForm.run( argv[j] ) );
printf("d: %s = %f\n", argv[j], dForm.run( argv[j] ) );
}
return 0;
}
|