Class Calculator
In: app/models/calculator.rb
Parent: Object

Methods

acos   acosh   add   asin   asinh   atan   atanh   cos   cosh   div   dupl   e   exp   expt   log   log10   mult   neg   new   pi   pop   rcl   sin   sinh   sqrt   sto   sub   swap   tan   tanh  

Attributes

errmsg  [R] 
errmsg  [W] 
in_im  [R] 
in_im  [W] 
in_re  [R] 
in_re  [W] 
mem  [R] 
mem  [W] 
stk  [R] 
stk  [W] 

Public Class methods

[Source]

    # File app/models/calculator.rb, line 14
14:   def initialize(stk,rconst,cconst,errmsg,mem)
15:     @stk = stk
16:     @rconst = rconst
17:     @cconst = cconst
18:     @errmsg = errmsg
19:     @mem = mem
20:   end

Public Instance methods

[Source]

    # File app/models/calculator.rb, line 86
86:   def acos
87:     a = @stk.pop
88:     c = a.acos
89:     @stk.push(c)
90:   end

[Source]

     # File app/models/calculator.rb, line 101
101:   def acosh
102:     a = @stk.pop
103:     c = a.acosh
104:     @stk.push(c)
105:   end

[Source]

    # File app/models/calculator.rb, line 21
21:   def add
22:     b = @stk.pop
23:     a = @stk.pop
24:     c = a + b
25:     @stk.push(c)
26:   end

[Source]

    # File app/models/calculator.rb, line 81
81:   def asin
82:     a = @stk.pop
83:     c = a.asin
84:     @stk.push(c)
85:   end

[Source]

     # File app/models/calculator.rb, line 96
 96:   def asinh
 97:     a = @stk.pop
 98:     c = a.asinh
 99:     @stk.push(c)
100:   end

[Source]

    # File app/models/calculator.rb, line 91
91:   def atan
92:     a = @stk.pop
93:     c = a.atan
94:     @stk.push(c)
95:   end

[Source]

     # File app/models/calculator.rb, line 106
106:   def atanh
107:     a = @stk.pop
108:     c = a.atanh
109:     @stk.push(c)
110:   end

[Source]

    # File app/models/calculator.rb, line 56
56:   def cos
57:     a = @stk.pop
58:     c = a.cos
59:     @stk.push(c)
60:   end

[Source]

    # File app/models/calculator.rb, line 71
71:   def cosh
72:     a = @stk.pop
73:     c = a.cosh
74:     @stk.push(c)
75:   end

[Source]

    # File app/models/calculator.rb, line 39
39:   def div
40:     b = @stk.pop
41:     a = @stk.pop
42:     c = a / b
43:     @stk.push(c)
44:   end

[Source]

     # File app/models/calculator.rb, line 136
136:   def dupl
137:     a = @stk.pop
138:     @stk.push(a)
139:     @stk.push(a)
140:   end

[Source]

     # File app/models/calculator.rb, line 154
154:   def e
155:     c = Apc.new(@rconst.e,@rconst.zero)
156:     @stk.push(c)
157:   end

[Source]

     # File app/models/calculator.rb, line 121
121:   def exp
122:     a = @stk.pop
123:     c = a.exp
124:     @stk.push(c)
125:   end

[Source]

    # File app/models/calculator.rb, line 45
45:   def expt
46:     b = @stk.pop
47:     a = @stk.pop
48:     c = a ** b
49:     @stk.push(c)
50:   end

[Source]

     # File app/models/calculator.rb, line 111
111:   def log
112:     a = @stk.pop
113:     c = a.log
114:     @stk.push(c)
115:   end

[Source]

     # File app/models/calculator.rb, line 116
116:   def log10
117:     a = @stk.pop
118:     c = a.log10
119:     @stk.push(c)
120:   end

[Source]

    # File app/models/calculator.rb, line 33
33:   def mult
34:     b = @stk.pop
35:     a = @stk.pop
36:     c = a * b
37:     @stk.push(c)
38:   end

[Source]

     # File app/models/calculator.rb, line 131
131:   def neg
132:     a = @stk.pop
133:     c = a.neg
134:     @stk.push(c)
135:   end

[Source]

     # File app/models/calculator.rb, line 150
150:   def pi
151:     c = Apc.new(@rconst.pi,@rconst.zero)
152:     @stk.push(c)
153:   end

[Source]

     # File app/models/calculator.rb, line 141
141:   def pop
142:     a = @stk.pop
143:   end

[Source]

     # File app/models/calculator.rb, line 161
161:   def rcl(pos)
162:     m = @mem[pos] 
163:     @stk.push(m)
164:   end

[Source]

    # File app/models/calculator.rb, line 51
51:   def sin
52:     a = @stk.pop
53:     c = a.sin
54:     @stk.push(c)
55:   end

[Source]

    # File app/models/calculator.rb, line 66
66:   def sinh
67:     a = @stk.pop
68:     c = a.sinh
69:     @stk.push(c)
70:   end

[Source]

     # File app/models/calculator.rb, line 126
126:   def sqrt
127:     a = @stk.pop
128:     c = a.sqrt
129:     @stk.push(c)
130:   end

[Source]

     # File app/models/calculator.rb, line 158
158:   def sto(pos)
159:     @mem[pos] = @stk.last
160:   end

[Source]

    # File app/models/calculator.rb, line 27
27:   def sub
28:     b = @stk.pop
29:     a = @stk.pop
30:     c = a - b
31:     @stk.push(c)
32:   end

[Source]

     # File app/models/calculator.rb, line 144
144:   def swap
145:     a = @stk.pop
146:     b = @stk.pop
147:     @stk.push(a)
148:     @stk.push(b)
149:   end

[Source]

    # File app/models/calculator.rb, line 61
61:   def tan
62:     a = @stk.pop
63:     c = a.tan
64:     @stk.push(c)
65:   end

[Source]

    # File app/models/calculator.rb, line 76
76:   def tanh
77:     a = @stk.pop
78:     c = a.tanh
79:     @stk.push(c)
80:   end

[Validate]