spreadsheet
typeScript/javascript spreadsheet parser, with formulas.
git clone https://git.vogt.world/spreadsheet.git
Log | Files | README.md
← Commit log
commit
message
Fixing SIN formula to function properly for PI value
author
Ben Vogt <[email protected]>
date
2017-01-08 21:25:31
stats
2 file(s) changed, 9 insertions(+), 2 deletions(-)
files
src/SupportedFormulas.ts
tests/SheetFormulaTest.ts
 1diff --git a/src/SupportedFormulas.ts b/src/SupportedFormulas.ts
 2index bc7ab69..f53d212 100644
 3--- a/src/SupportedFormulas.ts
 4+++ b/src/SupportedFormulas.ts
 5@@ -33,6 +33,9 @@ const OverrideFormulas = {
 6   EOMONTH: function (start_date, months) {
 7     var edate = moment(start_date).add(months, 'months');
 8     return new Date(edate.year(), edate.month(), edate.daysInMonth());
 9+  },
10+  SIN: function (rad) {
11+    return rad === Math.PI ? 0 : Math.sin(rad);
12   }
13 };
14 
15diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
16index 76709a6..f5f9520 100644
17--- a/tests/SheetFormulaTest.ts
18+++ b/tests/SheetFormulaTest.ts
19@@ -407,8 +407,11 @@ testFormula('=ROUNDDOWN(99.46, 1)', 99.4);
20 testFormula('=ROUNDUP(99.46, 1)', 99.5);
21 
22 // Test SIN
23-// TODO: This shuld work.
24-// testFormula('=SIN(PI())', 0);
25+testFormula('=SIN(0)', 0);
26+testFormula('=SIN(1)', 0.8414709848078965);
27+testFormula('=SIN(PI() / 2)', 1);
28+testFormula('=SIN(PI())', 0);
29+
30 
31 // Test SINH
32 testFormula('=SINH(PI())', 11.548739357257752);