Skip to content

Commit

Permalink
fix: formula calculation fails '=6^4-4^4' #83
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiooshiro committed Nov 2, 2022
1 parent b60e928 commit 3fcc2d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xlsx-calc",
"version": "0.7.6",
"version": "0.7.7",
"description": "A simple xlsx formula calculator.",
"main": "src/index.js",
"repository": "git@github.com:fabiooshiro/xlsx-calc.git",
Expand Down
2 changes: 1 addition & 1 deletion src/Exp.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ module.exports = function Exp(formula) {

self.calc = function() {
let args = self.args.concat();
exec_minus(args);
exec('^', args, function(a, b) {
return Math.pow(+a, +b);
});
exec_minus(args);
exec('/', args, function(a, b) {
if (b == 0) {
throw Error('#DIV/0!');
Expand Down
5 changes: 5 additions & 0 deletions test/2-bug-fix-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ describe('Bugs', function() {
XLSX_CALC(workbook);
assert.equal(workbook.Sheets.Sheet1.A2.v, true);
});
it('should calc 6^4-4^4 = 1040', function() {
workbook.Sheets.Sheet1.A2.f = '6^4-4^4';
XLSX_CALC(workbook);
assert.equal(workbook.Sheets.Sheet1.A2.v, 1040);
});
it('should consider the end of string', function() {
workbook.Sheets.Sheet1.A1.f = 'IF($C$3<=0,"Tempo de Investimento Invalido",IF($C$3<=24,"x","y"))';
workbook.Sheets.Sheet1.C3 = { v: 24 };
Expand Down

0 comments on commit 3fcc2d2

Please sign in to comment.