excel_to_code 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c755ed176f71493a5c52591c5170f6b958f90dd7
4
- data.tar.gz: 0575ab1ca5b705fc1520b0a81064a2f7f492ec32
3
+ metadata.gz: 5a9204f1b847531abe1231be586e07efde9d6f56
4
+ data.tar.gz: 55e3970859d6b607b877e91c4670777c098e5d78
5
5
  SHA512:
6
- metadata.gz: 6c8b064f12d8c64260b4694aeb77b5335a6b5fc431656a333cdb0cdebf60dc52d97a8ea58e505e7347a6fc3f6258cf7a7b8646c55f6a0ab043eb14b8915af7dd
7
- data.tar.gz: 666690943ce80993facb30315918fc46dd2617d5797dcdb62ecea6ba268ad3eb2c49f5bd5cfd9e5faa2585bfc27dc35e22c4649aa30e9dc5d3d1ae729e53fd6a
6
+ metadata.gz: 994609e98432c12a0abe413587fe7cefa9c138aedd43e174c1ff54a349bf716ed7e82e05413fab9f94b5291df2a1ff89881226c1559593a9052ff20c204ef9ef
7
+ data.tar.gz: 83139c0c54325b3303c64065b07d18a529a2a761de1391932388c41dc038d51c152bff100bf50c9e50066962eb5e45c136b996bcfba764f2fe025f2f0eb6a9c8
Binary file
@@ -63,6 +63,8 @@ static ExcelValue excel_index_2(ExcelValue array_v, ExcelValue row_number_v);
63
63
  static ExcelValue large(ExcelValue array_v, ExcelValue k_v);
64
64
  static ExcelValue left(ExcelValue string_v, ExcelValue number_of_characters_v);
65
65
  static ExcelValue left_1(ExcelValue string_v);
66
+ static ExcelValue excel_log(ExcelValue number);
67
+ static ExcelValue excel_log_2(ExcelValue number, ExcelValue base);
66
68
  static ExcelValue max(int number_of_arguments, ExcelValue *arguments);
67
69
  static ExcelValue min(int number_of_arguments, ExcelValue *arguments);
68
70
  static ExcelValue mod(ExcelValue a_v, ExcelValue b_v);
@@ -86,6 +88,7 @@ static ExcelValue text(ExcelValue number_v, ExcelValue format_v);
86
88
  static ExcelValue vlookup_3(ExcelValue lookup_value_v,ExcelValue lookup_table_v, ExcelValue column_number_v);
87
89
  static ExcelValue vlookup(ExcelValue lookup_value_v,ExcelValue lookup_table_v, ExcelValue column_number_v, ExcelValue match_type_v);
88
90
 
91
+
89
92
  // My little heap for excel values
90
93
  ExcelValue cells[MAX_EXCEL_VALUE_HEAP_SIZE];
91
94
  int cell_counter = 0;
@@ -298,6 +301,23 @@ static ExcelValue add(ExcelValue a_v, ExcelValue b_v) {
298
301
  return new_excel_number(a + b);
299
302
  }
300
303
 
304
+ static ExcelValue excel_log(ExcelValue number) {
305
+ return excel_log_2(number, TEN);
306
+ }
307
+
308
+ static ExcelValue excel_log_2(ExcelValue number_v, ExcelValue base_v) {
309
+ CHECK_FOR_PASSED_ERROR(number_v)
310
+ CHECK_FOR_PASSED_ERROR(base_v)
311
+ NUMBER(number_v, n)
312
+ NUMBER(base_v, b)
313
+ CHECK_FOR_CONVERSION_ERROR
314
+
315
+ if(n<=0) { return NUM; }
316
+ if(b<=0) { return NUM; }
317
+
318
+ return new_excel_number(log(n)/log(b));
319
+ }
320
+
301
321
  static ExcelValue excel_and(int array_size, ExcelValue *array) {
302
322
  int i;
303
323
  ExcelValue current_excel_value, array_result;
@@ -2385,6 +2405,16 @@ int test_functions() {
2385
2405
  assert(strcmp(text(BLANK, new_excel_string("0%")).string, "0%") == 0);
2386
2406
  assert(strcmp(text(new_excel_number(1.0), BLANK).string, "") == 0);
2387
2407
  assert(strcmp(text(new_excel_string("ASGASD"), new_excel_string("0%")).string, "ASGASD") == 0);
2408
+
2409
+ // Test LOG
2410
+ // One argument variant assumes LOG base 10
2411
+ assert(excel_log(new_excel_number(10)).number == 1);
2412
+ assert(excel_log(new_excel_number(100)).number == 2);
2413
+ assert(excel_log(new_excel_number(0)).type == ExcelError);
2414
+ // Two argument variant allows LOG base to be specified
2415
+ assert(excel_log_2(new_excel_number(8),new_excel_number(2)).number == 3.0);
2416
+ assert(excel_log_2(new_excel_number(8),new_excel_number(0)).type == ExcelError);
2417
+
2388
2418
  // Release memory
2389
2419
  free_all_allocated_memory();
2390
2420
 
@@ -47,6 +47,8 @@ class MapFormulaeToC < MapValuesToC
47
47
  'LARGE' => 'large',
48
48
  'LEFT1' => 'left_1',
49
49
  'LEFT2' => 'left',
50
+ 'LOG1' => 'excel_log',
51
+ 'LOG2' => 'excel_log_2',
50
52
  'MATCH2' => 'excel_match_2',
51
53
  'MATCH3' => 'excel_match',
52
54
  'MAX' => 'max',
@@ -69,7 +71,8 @@ class MapFormulaeToC < MapValuesToC
69
71
  'SUMPRODUCT' => 'sumproduct',
70
72
  'VLOOKUP3' => 'vlookup_3',
71
73
  'VLOOKUP4' => 'vlookup',
72
- '^' => 'power'
74
+ '^' => 'power',
75
+ 'POWER' => 'power'
73
76
  }
74
77
 
75
78
  def prefix(symbol,ast)
@@ -32,6 +32,7 @@ class MapFormulaeToRuby < MapValuesToRuby
32
32
  'INT' => 'int',
33
33
  'LARGE' => 'large',
34
34
  'LEFT' => 'left',
35
+ 'LOG' => 'log',
35
36
  'MATCH' => 'excel_match',
36
37
  'MAX' => 'max',
37
38
  'MID' => 'mid',
@@ -39,6 +40,7 @@ class MapFormulaeToRuby < MapValuesToRuby
39
40
  'MOD' => 'mod',
40
41
  'PI' => 'pi',
41
42
  'PMT' => 'pmt',
43
+ 'POWER' => 'power',
42
44
  'PV' => 'pv',
43
45
  'ROUND' => 'round',
44
46
  'ROUNDDOWN' => 'rounddown',
@@ -81,3 +81,5 @@ require_relative 'excel_functions/pv'
81
81
  require_relative 'excel_functions/text'
82
82
 
83
83
  require_relative 'excel_functions/hlookup'
84
+
85
+ require_relative 'excel_functions/log'
@@ -0,0 +1,17 @@
1
+ module ExcelFunctions
2
+
3
+ def log(a, b = 10)
4
+ a = number_argument(a)
5
+ b = number_argument(b)
6
+
7
+ return a if a.is_a?(Symbol)
8
+ return b if b.is_a?(Symbol)
9
+
10
+ return :num if a <= 0
11
+ return :num if b <= 0
12
+
13
+ Math.log(a) / Math.log(b)
14
+
15
+ end
16
+
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excel_to_code
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Counsell, Green on Black Ltd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2013-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -98,6 +98,7 @@ files:
98
98
  - src/commands/excel_to_ruby.rb
99
99
  - src/commands/excel_to_x.rb
100
100
  - src/commands.rb
101
+ - src/compile/c/a.out
101
102
  - src/compile/c/compile_named_reference_setters.rb
102
103
  - src/compile/c/compile_to_c.rb
103
104
  - src/compile/c/compile_to_c_header.rb
@@ -140,6 +141,7 @@ files:
140
141
  - src/excel/excel_functions/left.rb
141
142
  - src/excel/excel_functions/less_than.rb
142
143
  - src/excel/excel_functions/less_than_or_equal.rb
144
+ - src/excel/excel_functions/log.rb
143
145
  - src/excel/excel_functions/max.rb
144
146
  - src/excel/excel_functions/mid.rb
145
147
  - src/excel/excel_functions/min.rb