excel_to_code 0.3.16 → 0.3.17
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.
- checksums.yaml +4 -4
- data/src/commands/excel_to_x.rb +1 -0
- data/src/compile/c/a.out +0 -0
- data/src/compile/c/a.out.dSYM/Contents/Resources/DWARF/a.out +0 -0
- data/src/compile/c/excel_to_c_runtime.c +11 -0
- data/src/compile/c/excel_to_c_runtime_test.c +11 -1
- data/src/compile/c/map_formulae_to_c.rb +1 -0
- data/src/compile/ruby/map_formulae_to_ruby.rb +1 -0
- data/src/excel/excel_functions.rb +2 -0
- data/src/excel/excel_functions/number_argument.rb +1 -1
- data/src/excel/excel_functions/number_or_zero.rb +9 -0
- data/src/excel_to_code.rb +1 -1
- data/src/simplify/map_formulae_to_values.rb +7 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6c7853f4e0ce66da8f073d561bbd0dabd2a390d
|
4
|
+
data.tar.gz: b9e44bda2488d15ede19254374a9b19fb1320762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed1ca40db11c54a816035989e1f68427028dbd2ed3c7328e134efa225842b52c72e6db1df32090d75a45da8d95caa29102b52a028d413ff397ecd946d4dfed9
|
7
|
+
data.tar.gz: 87131c81c57f7d7705833b0f18f14e797fb553c304367f47c688c1c6593feaebd9589e278fbb92792add54442cdfa833508187ff090fd60169754f9332c0486a
|
data/src/commands/excel_to_x.rb
CHANGED
data/src/compile/c/a.out
CHANGED
Binary file
|
Binary file
|
@@ -85,6 +85,7 @@ static ExcelValue min(int number_of_arguments, ExcelValue *arguments);
|
|
85
85
|
static ExcelValue mmult(ExcelValue a_v, ExcelValue b_v);
|
86
86
|
static ExcelValue mod(ExcelValue a_v, ExcelValue b_v);
|
87
87
|
static ExcelValue negative(ExcelValue a_v);
|
88
|
+
static ExcelValue number_or_zero(ExcelValue maybe_number_v);
|
88
89
|
static ExcelValue npv(ExcelValue rate, int number_of_arguments, ExcelValue *arguments);
|
89
90
|
static ExcelValue pmt(ExcelValue rate_v, ExcelValue number_of_periods_v, ExcelValue present_value_v);
|
90
91
|
static ExcelValue pmt_4(ExcelValue rate_v, ExcelValue number_of_periods_v, ExcelValue present_value_v, ExcelValue final_value_v);
|
@@ -341,6 +342,16 @@ static ExcelValue ensure_is_number(ExcelValue maybe_number_v) {
|
|
341
342
|
return EXCEL_NUMBER(maybe_number);
|
342
343
|
}
|
343
344
|
|
345
|
+
static ExcelValue number_or_zero(ExcelValue maybe_number_v) {
|
346
|
+
if(maybe_number_v.type == ExcelNumber) {
|
347
|
+
return maybe_number_v;
|
348
|
+
}
|
349
|
+
if(maybe_number_v.type == ExcelError) {
|
350
|
+
return maybe_number_v;
|
351
|
+
}
|
352
|
+
return ZERO;
|
353
|
+
}
|
354
|
+
|
344
355
|
static ExcelValue excel_log(ExcelValue number) {
|
345
356
|
return excel_log_2(number, TEN);
|
346
357
|
}
|
@@ -955,7 +955,17 @@ int test_functions() {
|
|
955
955
|
assert(ensure_is_number(EXCEL_STRING("1.3")).number == 1.3);
|
956
956
|
assert(ensure_is_number(EXCEL_STRING("BASDASD")).type == ExcelError);
|
957
957
|
assert(ensure_is_number(DIV0).type == ExcelError);
|
958
|
-
|
958
|
+
|
959
|
+
// Tests ther NUMBER_OR_ZERO function
|
960
|
+
assert_equal(ZERO, number_or_zero(ZERO), "number_or_zero 0");
|
961
|
+
assert_equal(ONE, number_or_zero(ONE), "number_or_zero 1");
|
962
|
+
assert_equal(VALUE, number_or_zero(VALUE), "number_or_zero :error");
|
963
|
+
assert_equal(ZERO, number_or_zero(TRUE), "number_or_zero true");
|
964
|
+
assert_equal(ZERO, number_or_zero(FALSE), "number_or_zero false");
|
965
|
+
assert_equal(ZERO, number_or_zero(BLANK), "number_or_zero blank");
|
966
|
+
assert_equal(ZERO, number_or_zero(EXCEL_STRING("1.3")), "number_or_zero '1.3'");
|
967
|
+
assert_equal(ZERO, number_or_zero(EXCEL_STRING("Aasdfadsf")), "number_or_zero 'Asdfad'");
|
968
|
+
|
959
969
|
// RIGHT(string,[characters])
|
960
970
|
// ... should return the right n characters from a string
|
961
971
|
assert(strcmp(right_1(EXCEL_STRING("ONE")).string,"E") == 0);
|
data/src/excel_to_code.rb
CHANGED
@@ -97,6 +97,11 @@ class MapFormulaeToValues
|
|
97
97
|
return ast if ast[0] == :function && ast[1] == :ENSURE_IS_NUMBER
|
98
98
|
[:function, :ENSURE_IS_NUMBER, ast]
|
99
99
|
end
|
100
|
+
|
101
|
+
def number_or_zero(ast)
|
102
|
+
return ast if ast[0] == :function && ast[1] == :NUMBER_OR_ZERO
|
103
|
+
[:function, :NUMBER_OR_ZERO, ast]
|
104
|
+
end
|
100
105
|
|
101
106
|
def comparison(ast)
|
102
107
|
left, operator, right = ast[1], ast[2], ast[3]
|
@@ -336,12 +341,12 @@ class MapFormulaeToValues
|
|
336
341
|
# FIXME: Will I be haunted by this? What if doing a sum of something that isn't a number
|
337
342
|
# and so what is expected is a VALUE error?. YES. This doesn't work well.
|
338
343
|
elsif ast.length == 3 && [:cell, :sheet_reference].include?(ast[2].first)
|
339
|
-
new_ast =
|
344
|
+
new_ast = number_or_zero(ast[2])
|
340
345
|
if new_ast != ast
|
341
346
|
@replacements_made_in_the_last_pass += 1
|
342
347
|
ast.replace(new_ast)
|
343
348
|
end
|
344
|
-
elsif ast.length == 3 && ast[2][0] == :function && ast[2][1] == :
|
349
|
+
elsif ast.length == 3 && ast[2][0] == :function && ast[2][1] == :NUMBER_OR_ZERO
|
345
350
|
new_ast = ast[2]
|
346
351
|
if new_ast != ast
|
347
352
|
@replacements_made_in_the_last_pass += 1
|
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.3.
|
4
|
+
version: 0.3.17
|
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: 2015-05-
|
11
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- src/excel/excel_functions/not_equal.rb
|
198
198
|
- src/excel/excel_functions/npv.rb
|
199
199
|
- src/excel/excel_functions/number_argument.rb
|
200
|
+
- src/excel/excel_functions/number_or_zero.rb
|
200
201
|
- src/excel/excel_functions/pi.rb
|
201
202
|
- src/excel/excel_functions/pmt.rb
|
202
203
|
- src/excel/excel_functions/power.rb
|