OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Functions implemented: | 5 // Functions implemented: |
6 // | 6 // |
7 // ABS ACOS ACOSH AND ASIN ASINH ATAN ATAN2 ATANH COLUMNS COMBIN CONCATENATE COS COSH COUNTA DATE | 7 // ABS ACOS ACOSH AND ASIN ASINH ATAN ATAN2 ATANH COLUMNS COMBIN CONCATENATE COS COSH COUNTA DATE |
8 // DAY DEGREES EVEN EXP FACT FACTDOUBLE FALSE GCD HLOOKUP HOUR IF INT LARGE LCM LEN LN LOG | 8 // DAY DEGREES EVEN EXP FACT FACTDOUBLE FALSE GCD HLOOKUP HOUR IF INT LARGE LCM LEN LN LOG |
9 // LOG10 MATCH MAX MID MIN MINUTE MOD MONTH MULTINOMIAL NOT NOW ODD OFFSET OR PI POWER | 9 // LOG10 MATCH MAX MID MIN MINUTE MOD MONTH MULTINOMIAL NOT NOW ODD OFFSET OR PI POWER |
10 // PRODUCT QUOTIENT RADIANS RAND RANDBETWEEN RIGHT ROUND SECOND SERIESSUM SIGN | 10 // PRODUCT QUOTIENT RADIANS RAND RANDBETWEEN RIGHT ROUND SECOND SERIESSUM SIGN |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
588 stack[top] = new BooleanValue(true); | 588 stack[top] = new BooleanValue(true); |
589 }); | 589 }); |
590 _newFunc("CONCATENATE", -2, | 590 _newFunc("CONCATENATE", -2, |
591 void _(CellLocation location, List<Value> stack, int top, int nargs) { | 591 void _(CellLocation location, List<Value> stack, int top, int nargs) { |
592 StringBuffer sb = new StringBuffer(); | 592 StringBuffer sb = new StringBuffer(); |
593 for (int i = 0; i < nargs; i++) { | 593 for (int i = 0; i < nargs; i++) { |
594 sb.add(stack[top + i].asString(location)); | 594 sb.add(stack[top + i].asString(location)); |
595 } | 595 } |
596 stack[top] = new StringValue(sb.toString()); | 596 stack[top] = new StringValue(sb.toString()); |
597 }); | 597 }); |
598 _newFunc("COUNT", -1, void _(CellLocation location, List<Value> stack, int t op, int nargs) { | 598 _newFunc("COUNT", -1, (CellLocation location, List<Value> stack, int top, in t nargs) { |
zundel
2011/12/19 16:29:14
I would leave these statments unchanged. They are
scheglov
2011/12/19 19:10:38
I've restored types, but I have to tweak function
| |
599 int count = 0; | 599 int count = 0; |
600 for (int i = 0; i < nargs; i++) { | 600 for (int i = 0; i < nargs; i++) { |
601 Value value = stack[top + i]; | 601 Value value = stack[top + i]; |
602 if (value.datatype == Value.TYPE_CELLREF || value.datatype == Value.TY PE_RANGE) { | 602 if (value.datatype == Value.TYPE_CELLREF || value.datatype == Value.TY PE_RANGE) { |
603 count += _countCellsInRange(value.asRangeToken().getCellRange(locati on), | 603 count += _countCellsInRange(value.asRangeToken().getCellRange(locati on), |
604 int _(Cell cell) { return cell.isNumeric() ? 1 : 0; }); | 604 (Cell cell) { return cell.isNumeric() ? 1 : 0; }); |
605 } else if (value.datatype == Value.TYPE_DOUBLE) { | 605 } else if (value.datatype == Value.TYPE_DOUBLE) { |
606 count++; | 606 count++; |
607 } | 607 } |
608 } | 608 } |
609 stack[top] = new DoubleValue(count.toDouble()); | 609 stack[top] = new DoubleValue(count.toDouble()); |
610 }); | 610 }); |
611 _newFunc("COUNTA", -1, void _(CellLocation location, List<Value> stack, int top, int nargs) { | 611 _newFunc("COUNTA", -1, (CellLocation location, List<Value> stack, int top, i nt nargs) { |
612 int count = 0; | 612 int count = 0; |
613 for (int i = 0; i < nargs; i++) { | 613 for (int i = 0; i < nargs; i++) { |
614 Value value = stack[top + i]; | 614 Value value = stack[top + i]; |
615 if (value.datatype == Value.TYPE_CELLREF || value.datatype == Value.TY PE_RANGE) { | 615 if (value.datatype == Value.TYPE_CELLREF || value.datatype == Value.TY PE_RANGE) { |
616 count += _countCellsInRange(value.asRangeToken().getCellRange(locati on), | 616 count += _countCellsInRange(value.asRangeToken().getCellRange(locati on), |
617 int _(Cell cell) { return cell.isEmpty() ? 0 : 1; }); | 617 (Cell cell) { return cell.isEmpty() ? 0 : 1; }); |
618 } else { | 618 } else { |
619 count++; | 619 count++; |
620 } | 620 } |
621 } | 621 } |
622 stack[top] = new DoubleValue(count.toDouble()); | 622 stack[top] = new DoubleValue(count.toDouble()); |
623 }); | 623 }); |
624 _newFunc("GCD", -2, void _(CellLocation location, List<Value> stack, int top , int nargs) { | 624 _newFunc("GCD", -2, void _(CellLocation location, List<Value> stack, int top , int nargs) { |
625 for (int i = 0; i < nargs; i++) { | 625 for (int i = 0; i < nargs; i++) { |
626 if (stack[top + i].asDouble(location) < 0.0) { | 626 if (stack[top + i].asDouble(location) < 0.0) { |
627 throw new NumberException(); | 627 throw new NumberException(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
707 double xpow = Math.pow(x, n); | 707 double xpow = Math.pow(x, n); |
708 double xstep = Math.pow(x, m); | 708 double xstep = Math.pow(x, m); |
709 double sum = 0.0; | 709 double sum = 0.0; |
710 for (int i = 3; i < nargs; i++) { | 710 for (int i = 3; i < nargs; i++) { |
711 sum += xpow * stack[top + i].asDouble(location); | 711 sum += xpow * stack[top + i].asDouble(location); |
712 xpow *= xstep; | 712 xpow *= xstep; |
713 } | 713 } |
714 stack[top] = new DoubleValue(sum); | 714 stack[top] = new DoubleValue(sum); |
715 }); | 715 }); |
716 | 716 |
717 _newFunc("MATCH", -2, void _(CellLocation location, List<Value> stack, int t op, int nargs) { | 717 _newFunc("MATCH", -2, (CellLocation location, List<Value> stack, int top, in t nargs) { |
718 double value = stack[top].asDouble(location); | 718 double value = stack[top].asDouble(location); |
719 RangeToken rt = stack[top + 1].asRangeToken(); | 719 RangeToken rt = stack[top + 1].asRangeToken(); |
720 CellRange range = rt.getCellRange(location); | 720 CellRange range = rt.getCellRange(location); |
721 | 721 |
722 int matchType = 1; | 722 int matchType = 1; |
723 if (nargs > 2) { | 723 if (nargs > 2) { |
724 matchType = stack[top + 2].asDouble(location).floor().toInt(); | 724 matchType = stack[top + 2].asDouble(location).floor().toInt(); |
725 } | 725 } |
726 | 726 |
727 // The range must be 1xN or Nx1 | 727 // The range must be 1xN or Nx1 |
728 if (range.rows > 1 && range.columns > 1) { | 728 if (range.rows > 1 && range.columns > 1) { |
729 throw new NumberException(); | 729 throw new NumberException(); |
730 } | 730 } |
731 | 731 |
732 int index = 1; | 732 int index = 1; |
733 double bestValue = matchType == 1 ? -1.0e100 : 1.0e100; | 733 double bestValue = matchType == 1 ? -1.0e100 : 1.0e100; |
734 int bestIndex = -1; | 734 int bestIndex = -1; |
735 range.forEach(_(CellLocation loc) { | 735 range.forEach((CellLocation loc) { |
736 Cell cell = loc.getCell(); | 736 Cell cell = loc.getCell(); |
737 if (cell != null) { | 737 if (cell != null) { |
738 double d = cell.getDoubleValue(); | 738 double d = cell.getDoubleValue(); |
739 if (d == value) { | 739 if (d == value) { |
740 bestIndex = index; | 740 bestIndex = index; |
741 return; | 741 return; |
742 } else if (matchType == 1 && d < value && d > bestValue) { | 742 } else if (matchType == 1 && d < value && d > bestValue) { |
743 bestValue = d; | 743 bestValue = d; |
744 bestIndex = index; | 744 bestIndex = index; |
745 } else if (matchType == -1 && d > value && d < bestValue) { | 745 } else if (matchType == -1 && d > value && d < bestValue) { |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
974 Cell resultCell = range.spreadsheet.getCell(horizontal ? | 974 Cell resultCell = range.spreadsheet.getCell(horizontal ? |
975 new RowCol(outRowCol, bestIndex) : new RowCol(bestIndex, outRowCol)); | 975 new RowCol(outRowCol, bestIndex) : new RowCol(bestIndex, outRowCol)); |
976 stack[top] = new DoubleValue(resultCell == null ? 0.0 : resultCell.getDoub leValue()); | 976 stack[top] = new DoubleValue(resultCell == null ? 0.0 : resultCell.getDoub leValue()); |
977 } | 977 } |
978 } | 978 } |
979 | 979 |
980 void _newFunc(String name, int nargs, NumericFunction f) { | 980 void _newFunc(String name, int nargs, NumericFunction f) { |
981 _functions[name] = new SpreadsheetFunction(name, nargs, f); | 981 _functions[name] = new SpreadsheetFunction(name, nargs, f); |
982 } | 982 } |
983 } | 983 } |
OLD | NEW |