File: LnExpression.h

package info (click to toggle)
primrose 6%2Bdfsg1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,300 kB
  • ctags: 3,385
  • sloc: cpp: 27,318; php: 765; ansic: 636; objc: 272; sh: 136; makefile: 95; perl: 67
file content (103 lines) | stat: -rw-r--r-- 1,742 bytes parent folder | download | duplicates (18)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Modification History 
 *
 * 2003-April-28   Jason Rohrer
 * Created.
 */
 

#ifndef LN_EXPRESSION_INCLUDED
#define LN_EXPRESSION_INCLUDED 
 
#include "Expression.h" 
#include "UnaryOperationExpression.h" 

#include <math.h>
 
/**
 * Expression implementation of a unary ln (natural log) operation. 
 *
 * @author Jason Rohrer 
 */
class LnExpression : public UnaryOperationExpression { 
    
    public:
        
        /**
         * Constructs a unary ln operation expression.
         *
         * Argument is destroyed when the class is destroyed.
         *
         * @param inArgument the argument.
         */
        LnExpression( Expression *inArgument );
        
        
        /**
         * A static version of getID().
         */
        static long staticGetID();
        
        
        // implements the Expression interface
        virtual double evaluate();
        virtual long getID();
        virtual void print();
        virtual Expression *copy();
        
    protected:
        static long mID;
        
    };



// static init
long LnExpression::mID = 10;



inline LnExpression::LnExpression( Expression *inArgument ) 
    : UnaryOperationExpression( inArgument ) {
    
    }



inline double LnExpression::evaluate() {
    return log( mArgument->evaluate() );
    }



inline long LnExpression::getID() {    
    return mID;
    }    



inline long LnExpression::staticGetID() {
    return mID;
    }



inline void LnExpression::print() {
    printf( "( ln" );
    
    mArgument->print();
    printf( " )" );
    }
            


inline Expression *LnExpression::copy() {
    LnExpression *copy =
        new LnExpression( mArgument->copy() );
    
    return copy;
    }        


    
#endif