maths 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -15,4 +15,3 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- lib/maths/calc.rb
data/README.md CHANGED
@@ -92,6 +92,58 @@ maths> sqrt 25
92
92
  = 5
93
93
  ```
94
94
 
95
+ Cubed Roots!
96
+ ```
97
+ maths> cbrt 27
98
+ = 3
99
+ ```
100
+
101
+ More Trig than you can shake a stick at!
102
+
103
+ ```
104
+ maths> sin 30
105
+ = -0.9880316240928618
106
+ maths> asin 30
107
+ = -0.9880316240928618
108
+ maths> sinh 30
109
+ = 5343237290762.231
110
+ maths> asinh 30
111
+ = 4.09462222433053
112
+ maths> cos 30
113
+ = 0.15425144988758405
114
+ maths> acos 1
115
+ = 0
116
+ maths> cosh 30
117
+ = 5343237290762.231
118
+ maths> acosh 30
119
+ = 4.0940666686320855
120
+ maths> tan 25
121
+ = -0.13352640702153587
122
+ maths> atan 25
123
+ = 1.5308176396716067
124
+ ```
125
+
126
+ Logarithms!
127
+
128
+ ```
129
+ maths> ln 25
130
+ = 3.2188758248682006
131
+ maths> log 25
132
+ = 1.3979400086720377
133
+ maths> log2 32
134
+ = 5
135
+ ```
136
+
137
+ Rounding!
138
+ ```
139
+ maths> floor 5.5
140
+ = 5
141
+ maths> ceiling 5.5
142
+ = 6
143
+ maths> round 5.5
144
+ = 6
145
+ ```
146
+
95
147
  Exponents!
96
148
  ```
97
149
  maths> 2 ^ 4
data/lib/maths/calc.rb ADDED
@@ -0,0 +1,341 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.9
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+ # Generated grammar file.
10
+ module Maths
11
+ class Calculator < Racc::Parser
12
+
13
+ module_eval(<<'...end calc.y/module_eval...', 'calc.y', 39)
14
+
15
+ def parse(str)
16
+ @q = []
17
+ until str.empty?
18
+ case str
19
+
20
+ # ignore whitespace
21
+ when /\A\s+/
22
+
23
+ # percentage handling
24
+ when /\Aas a percentage of/
25
+ @q.push [:PERCENTAGE_OF, $&]
26
+ when /\Aas a % of/
27
+ @q.push [:PERCENTAGE_OF, $&]
28
+ when /\Aas % of/
29
+ @q.push [:PERCENTAGE_OF, $&]
30
+ when /\Aas % of/
31
+ @q.push [:PERCENTAGE_OF, $&]
32
+
33
+ # special terms
34
+ when /\Api/
35
+ @q.push [:NUMBER, BigDecimal.new("3.14159265358979323846264338327")]
36
+
37
+ # variables and functions
38
+ when /\A[A-Za-z]+[0-9]*/
39
+ if Maths::Functions::FUNCTIONS.has_key?($&)
40
+ @q.push [:FUNC, $&]
41
+ else
42
+ @q.push [:VARIABLE, $&]
43
+ end
44
+ when /\A\$/
45
+ @q.push [:VARIABLE, $&]
46
+
47
+ # numbers
48
+ when /\A\d+(\.\d+)?([Ee]\d+)?/
49
+ @q.push [:NUMBER, BigDecimal.new($&)]
50
+ # when /\A\d+/
51
+ # @q.push [:NUMBER, BigDecimal.new($&)]
52
+ when /\A.|\n/o
53
+ s = $&
54
+ @q.push [s, s]
55
+ end
56
+ str = $'
57
+ end
58
+ @q.push [false, '$end']
59
+ do_parse
60
+ end
61
+
62
+ def next_token
63
+ @q.shift
64
+ end
65
+
66
+ ...end calc.y/module_eval...
67
+ ##### State transition tables begin ###
68
+
69
+ racc_action_table = [
70
+ 9, 16, 13, 14, 15, 21, 6, 10, 9, 4,
71
+ 22, 5, 8, 7, 6, 24, 9, 4, nil, 5,
72
+ 8, 7, 6, nil, 9, 4, nil, 5, 8, 19,
73
+ 6, nil, 9, 4, nil, 5, 8, 19, 6, nil,
74
+ 9, 4, nil, 5, 8, 19, 6, nil, 9, 4,
75
+ nil, 5, 8, 19, 6, nil, 9, 4, nil, 5,
76
+ 8, 19, 6, nil, 9, 4, nil, 5, 8, 19,
77
+ 6, nil, 9, 4, nil, 5, 8, 19, 6, nil,
78
+ 9, 4, nil, 5, 8, 19, 6, nil, 9, 4,
79
+ nil, 5, 8, 19, 6, nil, nil, 4, nil, 5,
80
+ 8, 19, 16, 13, 14, 15, 11, 12, 17, nil,
81
+ nil, nil, 33, 16, 13, 14, 15, 11, 12, 17,
82
+ nil, nil, 32, 16, 13, 14, 15, 11, 12, 17,
83
+ 16, 13, 14, 15, 11, 12, 17, 16, 13, 14,
84
+ 15, 11, 12, 17, 16, 13, 14, 15 ]
85
+
86
+ racc_action_check = [
87
+ 0, 26, 26, 26, 26, 6, 0, 1, 22, 0,
88
+ 7, 0, 0, 0, 22, 10, 17, 22, nil, 22,
89
+ 22, 22, 17, nil, 4, 17, nil, 17, 17, 17,
90
+ 4, nil, 5, 4, nil, 4, 4, 4, 5, nil,
91
+ 16, 5, nil, 5, 5, 5, 16, nil, 15, 16,
92
+ nil, 16, 16, 16, 15, nil, 9, 15, nil, 15,
93
+ 15, 15, 9, nil, 14, 9, nil, 9, 9, 9,
94
+ 14, nil, 11, 14, nil, 14, 14, 14, 11, nil,
95
+ 12, 11, nil, 11, 11, 11, 12, nil, 13, 12,
96
+ nil, 12, 12, 12, 13, nil, nil, 13, nil, 13,
97
+ 13, 13, 20, 20, 20, 20, 20, 20, 20, nil,
98
+ nil, nil, 20, 18, 18, 18, 18, 18, 18, 18,
99
+ nil, nil, 18, 31, 31, 31, 31, 31, 31, 31,
100
+ 2, 2, 2, 2, 2, 2, 2, 34, 34, 34,
101
+ 34, 34, 34, 34, 25, 25, 25, 25 ]
102
+
103
+ racc_action_pointer = [
104
+ -3, 7, 126, nil, 21, 29, -10, -1, nil, 53,
105
+ 15, 69, 77, 85, 61, 45, 37, 13, 109, nil,
106
+ 98, nil, 5, nil, nil, 140, -3, nil, nil, nil,
107
+ nil, 119, nil, nil, 133, nil ]
108
+
109
+ racc_action_default = [
110
+ -3, -19, -1, -2, -19, -19, -19, -13, -14, -19,
111
+ -19, -19, -19, -19, -19, -19, -19, -19, -19, -13,
112
+ -19, -12, -19, -15, 36, -4, -5, -6, -7, -8,
113
+ -9, -16, -10, -11, -17, -18 ]
114
+
115
+ racc_goto_table = [
116
+ 3, 2, 1, nil, nil, 18, 20, nil, nil, nil,
117
+ 23, nil, 25, 26, 27, 28, 29, 30, 31, nil,
118
+ nil, nil, 35, 34 ]
119
+
120
+ racc_goto_check = [
121
+ 3, 2, 1, nil, nil, 2, 2, nil, nil, nil,
122
+ 2, nil, 2, 2, 2, 2, 2, 2, 2, nil,
123
+ nil, nil, 3, 2 ]
124
+
125
+ racc_goto_pointer = [
126
+ nil, 2, 1, 0 ]
127
+
128
+ racc_goto_default = [
129
+ nil, nil, nil, nil ]
130
+
131
+ racc_reduce_table = [
132
+ 0, 0, :racc_error,
133
+ 1, 18, :_reduce_none,
134
+ 1, 18, :_reduce_none,
135
+ 0, 18, :_reduce_3,
136
+ 3, 19, :_reduce_4,
137
+ 3, 19, :_reduce_5,
138
+ 3, 19, :_reduce_6,
139
+ 3, 19, :_reduce_7,
140
+ 3, 19, :_reduce_8,
141
+ 3, 19, :_reduce_9,
142
+ 3, 19, :_reduce_10,
143
+ 3, 19, :_reduce_11,
144
+ 2, 19, :_reduce_12,
145
+ 1, 19, :_reduce_13,
146
+ 1, 19, :_reduce_none,
147
+ 2, 19, :_reduce_15,
148
+ 3, 19, :_reduce_16,
149
+ 3, 20, :_reduce_17,
150
+ 3, 20, :_reduce_18 ]
151
+
152
+ racc_reduce_n = 19
153
+
154
+ racc_shift_n = 36
155
+
156
+ racc_token_table = {
157
+ false => 0,
158
+ :error => 1,
159
+ :UMINUS => 2,
160
+ :FUNC => 3,
161
+ "^" => 4,
162
+ "*" => 5,
163
+ "/" => 6,
164
+ "%" => 7,
165
+ "+" => 8,
166
+ "-" => 9,
167
+ :PERCENTAGE_OF => 10,
168
+ "=" => 11,
169
+ "(" => 12,
170
+ ")" => 13,
171
+ "|" => 14,
172
+ :NUMBER => 15,
173
+ :VARIABLE => 16 }
174
+
175
+ racc_nt_base = 17
176
+
177
+ racc_use_result_var = true
178
+
179
+ Racc_arg = [
180
+ racc_action_table,
181
+ racc_action_check,
182
+ racc_action_default,
183
+ racc_action_pointer,
184
+ racc_goto_table,
185
+ racc_goto_check,
186
+ racc_goto_default,
187
+ racc_goto_pointer,
188
+ racc_nt_base,
189
+ racc_reduce_table,
190
+ racc_token_table,
191
+ racc_shift_n,
192
+ racc_reduce_n,
193
+ racc_use_result_var ]
194
+
195
+ Racc_token_to_s_table = [
196
+ "$end",
197
+ "error",
198
+ "UMINUS",
199
+ "FUNC",
200
+ "\"^\"",
201
+ "\"*\"",
202
+ "\"/\"",
203
+ "\"%\"",
204
+ "\"+\"",
205
+ "\"-\"",
206
+ "PERCENTAGE_OF",
207
+ "\"=\"",
208
+ "\"(\"",
209
+ "\")\"",
210
+ "\"|\"",
211
+ "NUMBER",
212
+ "VARIABLE",
213
+ "$start",
214
+ "target",
215
+ "exp",
216
+ "assign" ]
217
+
218
+ Racc_debug_parser = false
219
+
220
+ ##### State transition tables end #####
221
+
222
+ # reduce 0 omitted
223
+
224
+ # reduce 1 omitted
225
+
226
+ # reduce 2 omitted
227
+
228
+ module_eval(<<'.,.,', 'calc.y', 13)
229
+ def _reduce_3(val, _values, result)
230
+ result = 0
231
+ result
232
+ end
233
+ .,.,
234
+
235
+ module_eval(<<'.,.,', 'calc.y', 15)
236
+ def _reduce_4(val, _values, result)
237
+ result += val[2]
238
+ result
239
+ end
240
+ .,.,
241
+
242
+ module_eval(<<'.,.,', 'calc.y', 16)
243
+ def _reduce_5(val, _values, result)
244
+ result -= val[2]
245
+ result
246
+ end
247
+ .,.,
248
+
249
+ module_eval(<<'.,.,', 'calc.y', 17)
250
+ def _reduce_6(val, _values, result)
251
+ result *= val[2]
252
+ result
253
+ end
254
+ .,.,
255
+
256
+ module_eval(<<'.,.,', 'calc.y', 18)
257
+ def _reduce_7(val, _values, result)
258
+ result /= val[2]
259
+ result
260
+ end
261
+ .,.,
262
+
263
+ module_eval(<<'.,.,', 'calc.y', 19)
264
+ def _reduce_8(val, _values, result)
265
+ result %= val[2]
266
+ result
267
+ end
268
+ .,.,
269
+
270
+ module_eval(<<'.,.,', 'calc.y', 20)
271
+ def _reduce_9(val, _values, result)
272
+ result = result.power(val[2])
273
+ result
274
+ end
275
+ .,.,
276
+
277
+ module_eval(<<'.,.,', 'calc.y', 21)
278
+ def _reduce_10(val, _values, result)
279
+ result = val[1]
280
+ result
281
+ end
282
+ .,.,
283
+
284
+ module_eval(<<'.,.,', 'calc.y', 22)
285
+ def _reduce_11(val, _values, result)
286
+ result = val[1].abs
287
+ result
288
+ end
289
+ .,.,
290
+
291
+ module_eval(<<'.,.,', 'calc.y', 23)
292
+ def _reduce_12(val, _values, result)
293
+ result = -val[1]
294
+ result
295
+ end
296
+ .,.,
297
+
298
+ module_eval(<<'.,.,', 'calc.y', 24)
299
+ def _reduce_13(val, _values, result)
300
+ result = Brain.lookup(val[0])
301
+ result
302
+ end
303
+ .,.,
304
+
305
+ # reduce 14 omitted
306
+
307
+ module_eval(<<'.,.,', 'calc.y', 26)
308
+ def _reduce_15(val, _values, result)
309
+ result = Maths::Functions.exec(val[0], val[1])
310
+ result
311
+ end
312
+ .,.,
313
+
314
+ module_eval(<<'.,.,', 'calc.y', 27)
315
+ def _reduce_16(val, _values, result)
316
+ result = Percentage.build(val[0], val[2])
317
+ result
318
+ end
319
+ .,.,
320
+
321
+ module_eval(<<'.,.,', 'calc.y', 29)
322
+ def _reduce_17(val, _values, result)
323
+ result = Brain.assign(val[0], val[2])
324
+ result
325
+ end
326
+ .,.,
327
+
328
+ module_eval(<<'.,.,', 'calc.y', 30)
329
+ def _reduce_18(val, _values, result)
330
+ result = Brain.assign(val[0], val[2])
331
+ result
332
+ end
333
+ .,.,
334
+
335
+ def _reduce_none(val, _values, result)
336
+ val[0]
337
+ end
338
+
339
+ end # class Calculator
340
+
341
+ end
data/lib/maths/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maths
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maths
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,6 +43,7 @@ files:
43
43
  - bin/maths
44
44
  - lib/maths.rb
45
45
  - lib/maths/brain.rb
46
+ - lib/maths/calc.rb
46
47
  - lib/maths/calc.y
47
48
  - lib/maths/formatter.rb
48
49
  - lib/maths/functions.rb