Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(formula): add some math function (#2761)
wpxp123456344f4dd5f774
diff --git a/packages/engine-formula/src/engine/utils/math-kit.ts b/packages/engine-formula/src/engine/utils/math-kit.tsindex 0ac47259bf..ae4d398ce3 100644--- a/packages/engine-formula/src/engine/utils/math-kit.ts+++ b/packages/engine-formula/src/engine/utils/math-kit.ts@@ -43,7 +43,7 @@ export function divide(a: number, b: number): number {* @returns The rounded number.*/export function round(base: number, precision: number): number {- const factor = 10 ** Math.floor(precision);+ const factor = 10 ** Math.trunc(precision);const epsilon = baseEpsilon(base, factor);return Math.round(multiply(base, factor) + epsilon) / factor;}@@ -55,7 +55,7 @@ export function round(base: number, precision: number): number {* @returns The floored number.*/export function floor(base: number, precision: number): number {- const factor = 10 ** Math.floor(precision);+ const factor = 10 ** Math.trunc(precision);const epsilon = baseEpsilon(base, factor);return Math.floor(multiply(base, factor) + epsilon) / factor;}@@ -67,7 +67,7 @@ export function floor(base: number, precision: number): number {* @returns The ceiled number.*/export function ceil(base: number, precision: number): number {- const factor = 10 ** Math.floor(precision);+ const factor = 10 ** Math.trunc(precision);const epsilon = baseEpsilon(base, factor);return Math.ceil(multiply(base, factor) - epsilon) / factor;}diff --git a/packages/engine-formula/src/engine/value-object/array-value-object.ts b/packages/engine-formula/src/engine/value-object/array-value-object.tsindex c76aaef037..2a413608d7 100644--- a/packages/engine-formula/src/engine/value-object/array-value-object.ts+++ b/packages/engine-formula/src/engine/value-object/array-value-object.ts@@ -1047,6 +1047,15 @@ export class ArrayValueObject extends BaseValueObject {});}+ override cosh(): BaseValueObject {+ return this.map((currentValue) => {+ if (currentValue.isError()) {+ return currentValue;+ }+ return currentValue.cosh();+ });+ }+override acos(): BaseValueObject {return this.map((currentValue) => {if (currentValue.isError()) {diff --git a/packages/engine-formula/src/engine/value-object/base-value-object.ts b/packages/engine-formula/src/engine/value-object/base-value-object.tsindex ef1e58827e..998d96f7c9 100644--- a/packages/engine-formula/src/engine/value-object/base-value-object.ts+++ b/packages/engine-formula/src/engine/value-object/base-value-object.ts@@ -297,6 +297,11 @@ export class BaseValueObject extends ObjectClassType {return ErrorValueObject.create(ErrorType.VALUE);}+ cosh(): BaseValueObject {+ /** abstract */+ return ErrorValueObject.create(ErrorType.VALUE);+ }+acos(): BaseValueObject {/** abstract */return ErrorValueObject.create(ErrorType.VALUE);diff --git a/packages/engine-formula/src/engine/value-object/primitive-object.ts b/packages/engine-formula/src/engine/value-object/primitive-object.tsindex 07b45584bb..89a36c9a19 100644--- a/packages/engine-formula/src/engine/value-object/primitive-object.ts+++ b/packages/engine-formula/src/engine/value-object/primitive-object.ts@@ -125,6 +125,10 @@ export class NullValueObject extends BaseValueObject {return NumberValueObject.create(0).cos();}+ override cosh(): BaseValueObject {+ return NumberValueObject.create(0).cosh();+ }+override acos(): BaseValueObject {return NumberValueObject.create(0).acos();}@@ -343,6 +347,10 @@ export class BooleanValueObject extends BaseValueObject {return this._convertToNumber().cos();}+ override cosh(): BaseValueObject {+ return this._convertToNumber().cosh();+ }+override acos(): BaseValueObject {return this._convertToNumber().acos();}@@ -886,6 +894,22 @@ export class NumberValueObject extends BaseValueObject {return NumberValueObject.create(result);}+ override cosh(): BaseValueObject {+ const currentValue = this.getValue();++ if (!Number.isFinite(currentValue)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const result = Math.cosh(currentValue);++ if (!Number.isFinite(result)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return NumberValueObject.create(result);+ }+override acos(): BaseValueObject {const currentValue = this.getValue();@@ -1170,7 +1194,8 @@ export class NumberValueObject extends BaseValueObject {return ErrorValueObject.create(ErrorType.NUM);}- const result = round(currentValue, value);+ // for excel negative special handle+ const result = currentValue < 0 ? -round(Math.abs(currentValue), value) : round(currentValue, value);if (!Number.isFinite(result)) {return ErrorValueObject.create(ErrorType.NUM);@@ -1201,7 +1226,8 @@ export class NumberValueObject extends BaseValueObject {return ErrorValueObject.create(ErrorType.NUM);}- const result = floor(currentValue, value);+ // for excel negative special handle+ const result = currentValue < 0 ? -floor(Math.abs(currentValue), value) : floor(currentValue, value);if (!Number.isFinite(result)) {return ErrorValueObject.create(ErrorType.NUM);@@ -1232,7 +1258,8 @@ export class NumberValueObject extends BaseValueObject {return ErrorValueObject.create(ErrorType.NUM);}- const result = ceil(currentValue, value);+ // for excel negative special handle+ const result = currentValue < 0 ? -ceil(Math.abs(currentValue), value) : ceil(currentValue, value);if (!Number.isFinite(result)) {return ErrorValueObject.create(ErrorType.NUM);diff --git a/packages/engine-formula/src/functions/math/base/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/base/__tests__/index.spec.tsindex 24e738589c..dc88348de3 100644--- a/packages/engine-formula/src/functions/math/base/__tests__/index.spec.ts+++ b/packages/engine-formula/src/functions/math/base/__tests__/index.spec.ts@@ -20,7 +20,6 @@ import { FUNCTION_NAMES_MATH } from '../../function-names';import { Base } from '../index';import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';import { ErrorType } from '../../../../basics/error-type';-import type { BaseValueObject } from '../../../../engine/value-object/base-value-object';import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';@@ -32,28 +31,28 @@ describe('Test base function', () => {const number = NumberValueObject.create(15);const radix = NumberValueObject.create(2);const minLength = NumberValueObject.create(10);- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe('0000001111');});it('number value is 2**53', () => {const number = NumberValueObject.create(2 ** 53);const radix = NumberValueObject.create(2);- const result = testFunction.calculate(number, radix) as BaseValueObject;+ const result = testFunction.calculate(number, radix);expect(result.getValue()).toBe(ErrorType.NUM);});it('radix value is 1.5', () => {const number = NumberValueObject.create(15);const radix = NumberValueObject.create(1.5);- const result = testFunction.calculate(number, radix) as BaseValueObject;+ const result = testFunction.calculate(number, radix);expect(result.getValue()).toBe(ErrorType.NUM);});it('radix value is 37', () => {const number = NumberValueObject.create(15);const radix = NumberValueObject.create(37);- const result = testFunction.calculate(number, radix) as BaseValueObject;+ const result = testFunction.calculate(number, radix);expect(result.getValue()).toBe(ErrorType.NUM);});@@ -61,7 +60,7 @@ describe('Test base function', () => {const number = NumberValueObject.create(15);const radix = NumberValueObject.create(2);const minLength = NumberValueObject.create(-2);- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe(ErrorType.NUM);});@@ -69,7 +68,7 @@ describe('Test base function', () => {const number = StringValueObject.create('15');const radix = NumberValueObject.create(2);const minLength = StringValueObject.create('7');- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe('0001111');});@@ -77,7 +76,7 @@ describe('Test base function', () => {const number = StringValueObject.create('test');const radix = NumberValueObject.create(2);const minLength = StringValueObject.create('7');- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe(ErrorType.VALUE);});@@ -85,7 +84,7 @@ describe('Test base function', () => {const number = BooleanValueObject.create(true);const radix = NumberValueObject.create(2);const minLength = StringValueObject.create('7');- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe('0000001');});@@ -93,7 +92,7 @@ describe('Test base function', () => {const number = NullValueObject.create();const radix = NumberValueObject.create(2);const minLength = StringValueObject.create('7');- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe('0000000');});@@ -101,7 +100,7 @@ describe('Test base function', () => {const number = ErrorValueObject.create(ErrorType.NAME);const radix = NumberValueObject.create(2);const minLength = StringValueObject.create('7');- const result = testFunction.calculate(number, radix, minLength) as BaseValueObject;+ const result = testFunction.calculate(number, radix, minLength);expect(result.getValue()).toBe(ErrorType.NAME);});diff --git a/packages/engine-formula/src/functions/math/base/index.ts b/packages/engine-formula/src/functions/math/base/index.tsindex 31955718ec..c4eff897f7 100644--- a/packages/engine-formula/src/functions/math/base/index.ts+++ b/packages/engine-formula/src/functions/math/base/index.ts@@ -19,7 +19,7 @@ import { expandArrayValueObject } from '../../../engine/utils/array-object';import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';import type { BaseValueObject } from '../../../engine/value-object/base-value-object';import { ErrorValueObject } from '../../../engine/value-object/base-value-object';-import { StringValueObject } from '../../../engine/value-object/primitive-object';+import { NumberValueObject, StringValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';export class Base extends BaseFunction {@@ -58,65 +58,65 @@ export class Base extends BaseFunction {const radixArray = expandArrayValueObject(maxRowLength, maxColumnLength, radix, ErrorValueObject.create(ErrorType.NA));const minLengthArray = minLength ? expandArrayValueObject(maxRowLength, maxColumnLength, minLength, ErrorValueObject.create(ErrorType.NA)) : [];- const resultArray = numberArray.map((NumberItemValueObject, rowIndex, columnIndex) => {- let radixItemValueObject = radixArray.get(rowIndex, columnIndex) as BaseValueObject;- let minLengthItemValueObject = minLength ? (minLengthArray as ArrayValueObject).get(rowIndex, columnIndex) : {};+ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let radixObject = radixArray.get(rowIndex, columnIndex) as BaseValueObject;+ let minLengthObject = minLength ? (minLengthArray as ArrayValueObject).get(rowIndex, columnIndex) : NumberValueObject.create(0);- if (NumberItemValueObject.isString()) {- NumberItemValueObject = NumberItemValueObject.convertToNumberObjectValue();+ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();}- if (radixItemValueObject.isString()) {- radixItemValueObject = radixItemValueObject.convertToNumberObjectValue();+ if (radixObject.isString()) {+ radixObject = radixObject.convertToNumberObjectValue();}- if (minLength && (minLengthItemValueObject as BaseValueObject).isString()) {- minLengthItemValueObject = (minLengthItemValueObject as BaseValueObject).convertToNumberObjectValue();+ if (minLength && (minLengthObject as BaseValueObject).isString()) {+ minLengthObject = (minLengthObject as BaseValueObject).convertToNumberObjectValue();}- if (NumberItemValueObject.isString() || radixItemValueObject.isString() || (minLength && (minLengthItemValueObject as BaseValueObject).isString())) {+ if (numberObject.isString() || radixObject.isString() || (minLength && (minLengthObject as BaseValueObject).isString())) {return ErrorValueObject.create(ErrorType.VALUE);}- if (NumberItemValueObject.isError()) {- return NumberItemValueObject;+ if (numberObject.isError()) {+ return numberObject;}- if (radixItemValueObject.isError()) {- return radixItemValueObject as BaseValueObject;+ if (radixObject.isError()) {+ return radixObject as BaseValueObject;}- if (minLength && (minLengthItemValueObject as BaseValueObject).isError()) {- return minLengthItemValueObject as BaseValueObject;+ if (minLength && (minLengthObject as BaseValueObject).isError()) {+ return minLengthObject as BaseValueObject;}// Any non-integer number entered as an argument is truncated to an integer.- const NumberItemValue = Math.floor(+NumberItemValueObject.getValue());- const radixItemValue = Math.floor(+radixItemValueObject.getValue());- const minLengthItemValue = minLength ? Math.floor(+(minLengthItemValueObject as BaseValueObject).getValue()) : 0;+ const numberValue = Math.floor(+numberObject.getValue());+ const radixValue = Math.floor(+radixObject.getValue());+ const minLengthValue = minLength ? Math.floor(+(minLengthObject as BaseValueObject).getValue()) : 0;// The number that you want to convert. Must be an integer greater than or equal to 0 and less than 2^53.- if (NumberItemValue < 0 || NumberItemValue >= 2 ** 53) {+ if (numberValue < 0 || numberValue >= 2 ** 53) {return ErrorValueObject.create(ErrorType.NUM);}// The base radix that you want to convert the number into. Must be an integer greater than or equal to 2 and less than or equal to 36.- if (radixItemValue < 2 || radixItemValue > 36) {+ if (radixValue < 2 || radixValue > 36) {return ErrorValueObject.create(ErrorType.NUM);}// The minimum length of the returned string. Must be an integer greater than or equal to 0.- if (minLengthItemValue < 0) {+ if (minLengthValue < 0) {return ErrorValueObject.create(ErrorType.NUM);}- let result = NumberItemValue.toString(radixItemValue);+ let result = numberValue.toString(radixValue);- if (minLength && result.length < minLengthItemValue) {- result = new Array(minLengthItemValue - result.length + 1).join('0') + result;+ if (minLength && result.length < minLengthValue) {+ result = new Array(minLengthValue - result.length + 1).join('0') + result;}- return StringValueObject.create(result);+ return StringValueObject.create(result.toLocaleUpperCase());});if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {diff --git a/packages/engine-formula/src/functions/math/ceiling-math/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/ceiling-math/__tests__/index.spec.tsnew file mode 100644index 0000000000..affdff9ea6--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling-math/__tests__/index.spec.ts@@ -0,0 +1,139 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { CeilingMath } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test ceiling.math function', () => {+ const testFunction = new CeilingMath(FUNCTION_NAMES_MATH.CEILING_MATH);++ describe('CeilingMath', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('number < 0 and significance < 0 and mode is null', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(-2);+ });++ it('number < 0 and significance < 0 and mode is not null or 0', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const mode = NumberValueObject.create(22);+ const result = testFunction.calculate(number, significance, mode);+ expect(result.getValue()).toBe(-4);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('number and significance is array, mode is null or 0', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [3, 0, 0, 0, ErrorType.VALUE, 2.5, -48, 6, ErrorType.NA],+ ]);+ });++ it('number and significance is array, mode is not null or 0', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const mode = NumberValueObject.create(-23);+ const result = testFunction.calculate(number, significance, mode);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [3, 0, -2, 0, ErrorType.VALUE, 2.5, -51, 6, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/ceiling-math/index.ts b/packages/engine-formula/src/functions/math/ceiling-math/index.tsnew file mode 100644index 0000000000..80cdbff5ad--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling-math/index.ts@@ -0,0 +1,114 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { ceil } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class CeilingMath extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(number: BaseValueObject, significance?: BaseValueObject, mode?: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (significance?.isError()) {+ return significance;+ }++ if (mode?.isError()) {+ return mode;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getRowCount() : 1,+ mode?.isArray() ? (mode as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1,+ mode?.isArray() ? (mode as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = significance ? expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA)) : [];+ const modeArray = mode ? expandArrayValueObject(maxRowLength, maxColumnLength, mode, ErrorValueObject.create(ErrorType.NA)) : [];++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significance ? (significanceArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : NumberValueObject.create(1);+ let modeObject = mode ? (modeArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : NumberValueObject.create(0);++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ if (modeObject.isString()) {+ modeObject = modeObject.convertToNumberObjectValue();+ }++ if (modeObject.isError()) {+ return modeObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();+ const modeValue = +modeObject.getValue();++ if (numberValue === 0 || significanceValue === 0) {+ return NumberValueObject.create(0);+ }++ let result: number;++ if (numberValue < 0 && modeValue !== 0) {+ result = (significanceValue < 0 ? ceil(Math.abs(numberValue) / Math.abs(significanceValue), 0) : -ceil(Math.abs(numberValue) / significanceValue, 0)) * significanceValue;+ } else {+ result = (significanceValue < 0 ? -ceil(numberValue / Math.abs(significanceValue), 0) : ceil(numberValue / significanceValue, 0)) * significanceValue;+ }++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/ceiling-precise/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/ceiling-precise/__tests__/index.spec.tsnew file mode 100644index 0000000000..233044af7e--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling-precise/__tests__/index.spec.ts@@ -0,0 +1,108 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { CeilingPrecise } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test ceiling.precise function', () => {+ const testFunction = new CeilingPrecise(FUNCTION_NAMES_MATH.CEILING_PRECISE);++ describe('CeilingPrecise', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('number < 0 and significance < 0', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(-2);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const significance = StringValueObject.create('1');+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(22);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [3, 0, 0, 0, ErrorType.VALUE, 2.5, -48, 6, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/ceiling-precise/index.ts b/packages/engine-formula/src/functions/math/ceiling-precise/index.tsnew file mode 100644index 0000000000..41165ad619--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling-precise/index.ts@@ -0,0 +1,91 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { ceil } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class CeilingPrecise extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(number: BaseValueObject, significance?: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (significance?.isError()) {+ return significance;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = significance ? expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA)) : [];++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significance ? (significanceArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : NumberValueObject.create(1);++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();++ if (numberValue === 0 || significanceValue === 0) {+ return NumberValueObject.create(0);+ }++ const result = (significanceValue < 0 ? -ceil(numberValue / Math.abs(significanceValue), 0) : ceil(numberValue / significanceValue, 0)) * significanceValue;++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/ceiling/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/ceiling/__tests__/index.spec.tsnew file mode 100644index 0000000000..4dbfef18ac--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling/__tests__/index.spec.ts@@ -0,0 +1,108 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Ceiling } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test ceiling function', () => {+ const testFunction = new Ceiling(FUNCTION_NAMES_MATH.CEILING);++ describe('Ceiling', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('number > 0 and significance < 0', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(-1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const significance = StringValueObject.create('1');+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(22);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(3);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [3, 0, 0, 0, ErrorType.VALUE, 2.5, -51, ErrorType.NUM, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/ceiling/index.ts b/packages/engine-formula/src/functions/math/ceiling/index.tsnew file mode 100644index 0000000000..f498a29298--- /dev/null+++ b/packages/engine-formula/src/functions/math/ceiling/index.ts@@ -0,0 +1,95 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { ceil } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Ceiling extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, significance: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (significance.isError()) {+ return significance;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significanceArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();++ if (numberValue > 0 && significanceValue < 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (numberValue === 0 || significanceValue === 0) {+ return NumberValueObject.create(0);+ }++ const result = ceil(numberValue / significanceValue, 0) * significanceValue;++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/cosh/index.ts b/packages/engine-formula/src/functions/math/cosh/index.tsindex ce0271a4ac..8ddf7cdaae 100644--- a/packages/engine-formula/src/functions/math/cosh/index.ts+++ b/packages/engine-formula/src/functions/math/cosh/index.ts@@ -14,10 +14,7 @@* limitations under the License.*/-import { ErrorType } from '../../../basics/error-type';import type { BaseValueObject } from '../../../engine/value-object/base-value-object';-import { ErrorValueObject } from '../../../engine/value-object/base-value-object';-import { NumberValueObject } from '../../../engine/value-object/primitive-object';import { BaseFunction } from '../../base-function';export class Cosh extends BaseFunction {@@ -25,46 +22,15 @@ export class Cosh extends BaseFunction {override maxParams = 1;- override calculate(variant: BaseValueObject) {- if (variant.isString()) {- variant = variant.convertToNumberObjectValue();+ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();}- if (variant.isError()) {- return variant;+ if (number.isError()) {+ return number;}- if ((variant as BaseValueObject).isArray()) {- return (variant as BaseValueObject).map((currentValue) => {- if (currentValue.isError()) {- return currentValue;- }- return cosh(currentValue as BaseValueObject);- });- }-- return cosh(variant as BaseValueObject);+ return number.cosh();}}--function cosh(num: BaseValueObject) {- let currentValue = num.getValue();-- if (num.isBoolean()) {- currentValue = currentValue ? 1 : 0;- }-- if (!Number.isFinite(currentValue)) {- return ErrorValueObject.create(ErrorType.VALUE);- }-- currentValue = Number(currentValue);-- const result = Math.cosh(currentValue);-- if (Number.isNaN(result)) {- return ErrorValueObject.create(ErrorType.VALUE);- }-- return NumberValueObject.create(result);-}diff --git a/packages/engine-formula/src/functions/math/decimal/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/decimal/__tests__/index.spec.tsnew file mode 100644index 0000000000..897513a1b7--- /dev/null+++ b/packages/engine-formula/src/functions/math/decimal/__tests__/index.spec.ts@@ -0,0 +1,123 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Decimal } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';++describe('Test decimal function', () => {+ const testFunction = new Decimal(FUNCTION_NAMES_MATH.DECIMAL);++ describe('Decimal', () => {+ it('All value is normal', () => {+ const number = StringValueObject.create('abc');+ const radix = NumberValueObject.create(16);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(2748);+ });++ it('number value is 2**53', () => {+ const number = NumberValueObject.create(2 ** 53);+ const radix = NumberValueObject.create(2);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('radix value is 15.5', () => {+ const number = StringValueObject.create('abc');+ const radix = NumberValueObject.create(15.5);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(2427);+ });++ it('radix value is 37', () => {+ const number = NumberValueObject.create(15);+ const radix = NumberValueObject.create(37);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('value is normal string', () => {+ const number = StringValueObject.create('test');+ const radix = NumberValueObject.create(2);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const radix = NumberValueObject.create(2);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is blank cell', () => {+ const number = NullValueObject.create();+ const radix = NumberValueObject.create(2);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const radix = NumberValueObject.create(2);+ const result = testFunction.calculate(number, radix);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ ['9fb', ' ', 23, 'abc', false, null, ErrorType.NAME],+ ]),+ rowCount: 1,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const radix = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [true],+ ['16'],+ ['2.34'],+ ['test'],+ [-3],+ ]),+ rowCount: 5,+ columnCount: 1,+ unitId: '',+ sheetId: '',+ row: 8,+ column: 8,+ });+ const result = testFunction.calculate(number, radix);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NAME],+ [2555, 0, 35, 2748, ErrorType.NUM, 0, ErrorType.NAME],+ [ErrorType.NUM, 0, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, 0, ErrorType.NAME],+ [ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.VALUE, ErrorType.NAME],+ [ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NUM, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/decimal/index.ts b/packages/engine-formula/src/functions/math/decimal/index.tsnew file mode 100644index 0000000000..ef0c40f7b9--- /dev/null+++ b/packages/engine-formula/src/functions/math/decimal/index.ts@@ -0,0 +1,130 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Decimal extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(text: BaseValueObject, radix: BaseValueObject) {+ if (text.isError()) {+ return text;+ }++ if (radix.isError()) {+ return radix;+ }++ // get max row length+ const maxRowLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getRowCount() : 1,+ radix.isArray() ? (radix as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ text.isArray() ? (text as ArrayValueObject).getColumnCount() : 1,+ radix.isArray() ? (radix as ArrayValueObject).getColumnCount() : 1+ );++ const textArray = expandArrayValueObject(maxRowLength, maxColumnLength, text, ErrorValueObject.create(ErrorType.NA));+ const radixArray = expandArrayValueObject(maxRowLength, maxColumnLength, radix, ErrorValueObject.create(ErrorType.NA));++ const resultArray = textArray.map((textObject, rowIndex, columnIndex) => {+ let radixObject = radixArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (radixObject.isString()) {+ radixObject = radixObject.convertToNumberObjectValue();+ }++ if (radixObject.isString()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (textObject.isError()) {+ return textObject;+ }++ if (radixObject.isError()) {+ return radixObject;+ }++ const textValue = `${textObject.getValue()}`;+ const radixValue = Math.floor(+radixObject.getValue());++ // The number that you want to convert. Must be an integer greater than or equal to 0 and less than 2^53.+ if (isRealNum(textValue) && (+textValue < 0 || +textValue >= 2 ** 53 || !Number.isInteger(+textValue))) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (textValue.toLocaleLowerCase() === 'true' || textValue.toLocaleLowerCase() === 'false') {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ // The base radix that you want to convert the number into. Must be an integer greater than or equal to 2 and less than or equal to 36.+ if (radixValue < 2 || radixValue > 36) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (textValue.replace(/\s/g, '') === '') {+ return NumberValueObject.create(0);+ }++ if (!this.isValidCharForRadix(textValue, radixValue)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const result = Number.parseInt(textValue, radixValue);++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }++ private isValidCharForRadix(text: string, radix: number): boolean {+ for (const char of text) {+ const charCode = char.toUpperCase().charCodeAt(0);++ if (radix <= 10 && !(charCode >= 48 && charCode < 48 + radix)) { // '0' to 'radix-1'+ return false;+ }++ if (radix > 10 && !((charCode >= 48 && charCode < 58) || (charCode >= 65 && charCode < 65 + radix - 10))) { // '0' to '9' 'A' to 'A+radix-10'+ return false;+ }+ }++ return true;+ }+}diff --git a/packages/engine-formula/src/functions/math/degrees/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/degrees/__tests__/index.spec.tsnew file mode 100644index 0000000000..32286739dd--- /dev/null+++ b/packages/engine-formula/src/functions/math/degrees/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Degrees } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test degrees function', () => {+ const testFunction = new Degrees(FUNCTION_NAMES_MATH.DEGREES);++ describe('Degrees', () => {+ it('Value is normal number', () => {+ const angle = NumberValueObject.create(1);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(57.29577951308232);+ });++ it('Value is number valid', () => {+ const angle = NumberValueObject.create(-2);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(-114.59155902616465);+ });++ it('Value is number string', () => {+ const angle = StringValueObject.create('1.5');+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(85.94366926962348);+ });++ it('Value is normal string', () => {+ const angle = StringValueObject.create('test');+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const angle = BooleanValueObject.create(false);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(0);+ });+ it('Value is blank cell', () => {+ const angle = NullValueObject.create();+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(0);+ });+ it('Value is error', () => {+ const angle = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const angle = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, ' ', 5, -1.575, true, 'test'],+ [1, true, null, '2', false, -1],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(angle);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [123.18592595312698, ErrorType.VALUE, 286.4788975654116, -90.24085273310466, 57.29577951308232, ErrorType.VALUE],+ [57.29577951308232, 57.29577951308232, 0, 114.59155902616465, 0, -57.29577951308232],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/degrees/index.ts b/packages/engine-formula/src/functions/math/degrees/index.tsnew file mode 100644index 0000000000..5ddfe15fbd--- /dev/null+++ b/packages/engine-formula/src/functions/math/degrees/index.ts@@ -0,0 +1,73 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Degrees extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(angle: BaseValueObject) {+ if (angle.isString()) {+ angle = angle.convertToNumberObjectValue();+ }++ if (angle.isError()) {+ return angle;+ }++ if (angle.isArray()) {+ return angle.map((angleObject) => {+ if (angleObject.isError()) {+ return angleObject;+ }++ return this._handleSingleObject(angleObject);+ });+ }++ return this._handleSingleObject(angle);+ }++ private _handleSingleObject(angle: BaseValueObject) {+ if (angle.isString()) {+ angle = angle.convertToNumberObjectValue();+ }++ if (angle.isError()) {+ return angle;+ }++ const angleValue = +angle.getValue();++ if (!Number.isFinite(angleValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const result = angleValue * (180 / Math.PI);++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/even/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/even/__tests__/index.spec.tsnew file mode 100644index 0000000000..6c10e78ac0--- /dev/null+++ b/packages/engine-formula/src/functions/math/even/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Even } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test even function', () => {+ const testFunction = new Even(FUNCTION_NAMES_MATH.EVEN);++ describe('Even', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(1.5);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(2);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-1);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(-2);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('3.5');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(4);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(2);+ });+ it('Value is blank cell', () => {+ const number = NullValueObject.create();+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(0);+ });+ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, ' ', 5, -1.575, true, 'test', 1.98, -50.55, 5],+ [1, true, null, '2', false, -1, 2.5, -3, -2],+ ]),+ rowCount: 2,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [4, ErrorType.VALUE, 6, -2, 2, ErrorType.VALUE, 2, -52, 6],+ [2, 2, 0, 2, 0, -2, 4, -4, -2],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/even/index.ts b/packages/engine-formula/src/functions/math/even/index.tsnew file mode 100644index 0000000000..331f91d121--- /dev/null+++ b/packages/engine-formula/src/functions/math/even/index.ts@@ -0,0 +1,78 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import { ceil } from '../../../engine/utils/math-kit';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Even extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (number.isArray()) {+ return number.map((numberObject) => {+ if (numberObject.isError()) {+ return numberObject;+ }++ return this._handleSingleObject(numberObject);+ });+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ const numberValue = +number.getValue();++ if (!Number.isFinite(numberValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const result = (numberValue < 0 ? -ceil(Math.abs(numberValue) / 2, 0) : ceil(numberValue / 2, 0)) * 2;++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (result === 0) {+ return NumberValueObject.create(0);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/exp/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/exp/__tests__/index.spec.tsnew file mode 100644index 0000000000..1e491e12f2--- /dev/null+++ b/packages/engine-formula/src/functions/math/exp/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Exp } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test exp function', () => {+ const testFunction = new Exp(FUNCTION_NAMES_MATH.EXP);++ describe('Exp', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(2.718281828459045);+ });++ it('Value is number valid', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.1353352832366127);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(4.4816890703380645);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(false);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2.718281828459045, ErrorType.VALUE, 3.4212295362896734, 2.718281828459045, 1, 1],+ [1, 2.6881171418161356e+43, 10.381236562731843, ErrorType.VALUE, 0.049787068367863944, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/exp/index.ts b/packages/engine-formula/src/functions/math/exp/index.tsnew file mode 100644index 0000000000..069fceceb7--- /dev/null+++ b/packages/engine-formula/src/functions/math/exp/index.ts@@ -0,0 +1,36 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Exp extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(variant: BaseValueObject) {+ if (variant.isString()) {+ variant = variant.convertToNumberObjectValue();+ }++ if (variant.isError()) {+ return variant;+ }++ return variant.exp();+ }+}diff --git a/packages/engine-formula/src/functions/math/floor-math/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/floor-math/__tests__/index.spec.tsnew file mode 100644index 0000000000..33be3ce102--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor-math/__tests__/index.spec.ts@@ -0,0 +1,139 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { FloorMath } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test floor.math function', () => {+ const testFunction = new FloorMath(FUNCTION_NAMES_MATH.FLOOR_MATH);++ describe('FloorMath', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('number < 0 and significance < 0 and mode is null', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(-4);+ });++ it('number < 0 and significance < 0 and mode is not null or 0', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const mode = NumberValueObject.create(22);+ const result = testFunction.calculate(number, significance, mode);+ expect(result.getValue()).toBe(-2);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('number and significance is array, mode is null or 0', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2, 0, -2, 0, ErrorType.VALUE, 0, -51, 4, ErrorType.NA],+ ]);+ });++ it('number and significance is array, mode is not null or 0', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const mode = NumberValueObject.create(-23);+ const result = testFunction.calculate(number, significance, mode);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2, 0, 0, 0, ErrorType.VALUE, 0, -48, 4, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/floor-math/index.ts b/packages/engine-formula/src/functions/math/floor-math/index.tsnew file mode 100644index 0000000000..4c43fd0974--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor-math/index.ts@@ -0,0 +1,105 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { floor } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class FloorMath extends BaseFunction {+ override minParams = 1;++ override maxParams = 3;++ override calculate(number: BaseValueObject, significance?: BaseValueObject, mode?: BaseValueObject) {+ significance = significance ?? NumberValueObject.create(1);+ mode = mode ?? NumberValueObject.create(0);++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getRowCount() : 1,+ mode.isArray() ? (mode as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1,+ mode.isArray() ? (mode as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA));+ const modeArray = expandArrayValueObject(maxRowLength, maxColumnLength, mode, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significanceArray.get(rowIndex, columnIndex) as BaseValueObject;+ let modeObject = modeArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ if (modeObject.isString()) {+ modeObject = modeObject.convertToNumberObjectValue();+ }++ if (modeObject.isError()) {+ return modeObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();+ const modeValue = +modeObject.getValue();++ if (numberValue === 0 || significanceValue === 0) {+ return NumberValueObject.create(0);+ }++ let result: number;++ if (numberValue < 0 && modeValue !== 0) {+ result = (significanceValue < 0 ? floor(Math.abs(numberValue) / Math.abs(significanceValue), 0) : -floor(Math.abs(numberValue) / significanceValue, 0)) * significanceValue;+ } else {+ result = (significanceValue < 0 ? -floor(numberValue / Math.abs(significanceValue), 0) : floor(numberValue / significanceValue, 0)) * significanceValue;+ }++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/floor-precise/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/floor-precise/__tests__/index.spec.tsnew file mode 100644index 0000000000..fa2c067df5--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor-precise/__tests__/index.spec.ts@@ -0,0 +1,108 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { FloorPrecise } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test floor.precise function', () => {+ const testFunction = new FloorPrecise(FUNCTION_NAMES_MATH.FLOOR_PRECISE);++ describe('FloorPrecise', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('number < 0 and significance < 0', () => {+ const number = NumberValueObject.create(-2.5);+ const significance = NumberValueObject.create(-2);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(-4);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const significance = StringValueObject.create('1');+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(21);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2, 0, -2, 0, ErrorType.VALUE, 0, -51, 4, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/floor-precise/index.ts b/packages/engine-formula/src/functions/math/floor-precise/index.tsnew file mode 100644index 0000000000..a9cb04387a--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor-precise/index.ts@@ -0,0 +1,91 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { floor } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class FloorPrecise extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(number: BaseValueObject, significance?: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (significance?.isError()) {+ return significance;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance?.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = significance ? expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA)) : [];++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significance ? (significanceArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : NumberValueObject.create(1);++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();++ if (numberValue === 0 || significanceValue === 0) {+ return NumberValueObject.create(0);+ }++ const result = (significanceValue < 0 ? -floor(numberValue / Math.abs(significanceValue), 0) : floor(numberValue / significanceValue, 0)) * significanceValue;++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/floor/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/floor/__tests__/index.spec.tsnew file mode 100644index 0000000000..aef4b0f669--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor/__tests__/index.spec.ts@@ -0,0 +1,108 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Floor } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test floor function', () => {+ const testFunction = new Floor(FUNCTION_NAMES_MATH.FLOOR);++ describe('Floor', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('number > 0 and significance < 0', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NumberValueObject.create(-1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const significance = StringValueObject.create('1');+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(21);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const significance = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(2);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const significance = NullValueObject.create();+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const significance = NumberValueObject.create(1);+ const result = testFunction.calculate(number, significance);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, null, -1.575, '21.5', 'test', 1.98, '-50.55', 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const significance = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, significance);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2, 0, -2, ErrorType.DIV_BY_ZERO, ErrorType.VALUE, 0, -48, ErrorType.NUM, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/floor/index.ts b/packages/engine-formula/src/functions/math/floor/index.tsnew file mode 100644index 0000000000..4e7b1f1a94--- /dev/null+++ b/packages/engine-formula/src/functions/math/floor/index.ts@@ -0,0 +1,99 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { floor } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Floor extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, significance: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (significance.isError()) {+ return significance;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ significance.isArray() ? (significance as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const significanceArray = expandArrayValueObject(maxRowLength, maxColumnLength, significance, ErrorValueObject.create(ErrorType.NA));++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let significanceObject = significanceArray.get(rowIndex, columnIndex) as BaseValueObject;++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (significanceObject.isString()) {+ significanceObject = significanceObject.convertToNumberObjectValue();+ }++ if (significanceObject.isError()) {+ return significanceObject;+ }++ const numberValue = +numberObject.getValue();+ const significanceValue = +significanceObject.getValue();++ if (numberValue > 0 && significanceValue < 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ if (numberValue === 0) {+ return NumberValueObject.create(0);+ }++ if (significanceValue === 0) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const result = floor(numberValue / significanceValue, 0) * significanceValue;++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/function-map.ts b/packages/engine-formula/src/functions/math/function-map.tsindex 52e93ef257..61d280da0e 100644--- a/packages/engine-formula/src/functions/math/function-map.ts+++ b/packages/engine-formula/src/functions/math/function-map.ts@@ -14,6 +14,7 @@* limitations under the License.*/+import { FUNCTION_NAMES_MATH } from './function-names';import { Abs } from './abs';import { Acos } from './acos';import { Acosh } from './acosh';@@ -25,22 +26,52 @@ import { Atan } from './atan';import { Atan2 } from './atan2';import { Atanh } from './atanh';import { Base } from './base';+import { Ceiling } from './ceiling';+import { CeilingMath } from './ceiling-math';+import { CeilingPrecise } from './ceiling-precise';import { Cos } from './cos';import { Cosh } from './cosh';import { Cot } from './cot';import { Coth } from './coth';import { Csc } from './csc';import { Csch } from './csch';-import { FUNCTION_NAMES_MATH } from './function-names';+import { Decimal } from './decimal';+import { Degrees } from './degrees';+import { Even } from './even';+import { Exp } from './exp';+import { Floor } from './floor';+import { FloorMath } from './floor-math';+import { FloorPrecise } from './floor-precise';+import { Ln } from './ln';+import { Log } from './log';+import { Log10 } from './log10';import { Mod } from './mod';+import { Mround } from './mround';+import { Odd } from './odd';+import { Pi } from './pi';import { Power } from './power';import { Product } from './product';+import { Radians } from './radians';+import { Rand } from './rand';+import { Randarray } from './randarray';+import { Randbetween } from './randbetween';+import { Round } from './round';+import { Rounddown } from './rounddown';+import { Roundup } from './roundup';+import { Sec } from './sec';+import { Sech } from './sech';import { Sin } from './sin';import { Sinh } from './sinh';+import { Sqrt } from './sqrt';+import { Sqrtpi } from './sqrtpi';import { Subtotal } from './subtotal';import { Sum } from './sum';import { Sumif } from './sumif';import { Sumifs } from './sumifs';+import { Sumsq } from './sumsq';+import { Sumx2my2 } from './sumx2my2';+import { Sumx2py2 } from './sumx2py2';+import { Sumxmy2 } from './sumxmy2';import { Sumproduct } from './sumproduct';import { Tan } from './tan';import { Tanh } from './tanh';@@ -57,21 +88,52 @@ export const functionMath = [[Atan2, FUNCTION_NAMES_MATH.ATAN2],[Atanh, FUNCTION_NAMES_MATH.ATANH],[Base, FUNCTION_NAMES_MATH.BASE],+ [Ceiling, FUNCTION_NAMES_MATH.CEILING],+ [CeilingMath, FUNCTION_NAMES_MATH.CEILING_MATH],+ [CeilingPrecise, FUNCTION_NAMES_MATH.CEILING_PRECISE],[Cos, FUNCTION_NAMES_MATH.COS],[Cosh, FUNCTION_NAMES_MATH.COSH],[Cot, FUNCTION_NAMES_MATH.COT],[Coth, FUNCTION_NAMES_MATH.COTH],[Csc, FUNCTION_NAMES_MATH.CSC],[Csch, FUNCTION_NAMES_MATH.CSCH],+ [Decimal, FUNCTION_NAMES_MATH.DECIMAL],+ [Degrees, FUNCTION_NAMES_MATH.DEGREES],+ [Even, FUNCTION_NAMES_MATH.EVEN],+ [Exp, FUNCTION_NAMES_MATH.EXP],+ [Floor, FUNCTION_NAMES_MATH.FLOOR],+ [FloorMath, FUNCTION_NAMES_MATH.FLOOR_MATH],+ [FloorPrecise, FUNCTION_NAMES_MATH.FLOOR_PRECISE],+ [Log, FUNCTION_NAMES_MATH.LOG],+ [Ln, FUNCTION_NAMES_MATH.LN],+ [Log10, FUNCTION_NAMES_MATH.LOG10],[Mod, FUNCTION_NAMES_MATH.MOD],+ [Mround, FUNCTION_NAMES_MATH.MROUND],[Power, FUNCTION_NAMES_MATH.POWER],+ [Odd, FUNCTION_NAMES_MATH.ODD],+ [Pi, FUNCTION_NAMES_MATH.PI],[Product, FUNCTION_NAMES_MATH.PRODUCT],+ [Radians, FUNCTION_NAMES_MATH.RADIANS],+ [Rand, FUNCTION_NAMES_MATH.RAND],+ [Randarray, FUNCTION_NAMES_MATH.RANDARRAY],+ [Randbetween, FUNCTION_NAMES_MATH.RANDBETWEEN],+ [Round, FUNCTION_NAMES_MATH.ROUND],+ [Rounddown, FUNCTION_NAMES_MATH.ROUNDDOWN],+ [Roundup, FUNCTION_NAMES_MATH.ROUNDUP],+ [Sec, FUNCTION_NAMES_MATH.SEC],+ [Sech, FUNCTION_NAMES_MATH.SECH],[Sin, FUNCTION_NAMES_MATH.SIN],[Sinh, FUNCTION_NAMES_MATH.SINH],+ [Sqrt, FUNCTION_NAMES_MATH.SQRT],+ [Sqrtpi, FUNCTION_NAMES_MATH.SQRTPI],[Subtotal, FUNCTION_NAMES_MATH.SUBTOTAL],[Sum, FUNCTION_NAMES_MATH.SUM],[Sumif, FUNCTION_NAMES_MATH.SUMIF],[Sumifs, FUNCTION_NAMES_MATH.SUMIFS],+ [Sumsq, FUNCTION_NAMES_MATH.SUMSQ],+ [Sumx2my2, FUNCTION_NAMES_MATH.SUMX2MY2],+ [Sumx2py2, FUNCTION_NAMES_MATH.SUMX2PY2],+ [Sumxmy2, FUNCTION_NAMES_MATH.SUMXMY2],[Sumproduct, FUNCTION_NAMES_MATH.SUMPRODUCT],[Tan, FUNCTION_NAMES_MATH.TAN],[Tanh, FUNCTION_NAMES_MATH.TANH],diff --git a/packages/engine-formula/src/functions/math/ln/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/ln/__tests__/index.spec.tsnew file mode 100644index 0000000000..cf1306e3c2--- /dev/null+++ b/packages/engine-formula/src/functions/math/ln/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Ln } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test ln function', () => {+ const testFunction = new Ln(FUNCTION_NAMES_MATH.LN);++ describe('Ln', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });++ it('Value is number valid', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.4054651081081644);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0, ErrorType.VALUE, 0.2070141693843261, 0, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.NUM, 4.605170185988092, 0.85015092936961, ErrorType.VALUE, ErrorType.NUM, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/ln/index.ts b/packages/engine-formula/src/functions/math/ln/index.tsnew file mode 100644index 0000000000..da26d0433b--- /dev/null+++ b/packages/engine-formula/src/functions/math/ln/index.ts@@ -0,0 +1,36 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Ln extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(variant: BaseValueObject) {+ if (variant.isString()) {+ variant = variant.convertToNumberObjectValue();+ }++ if (variant.isError()) {+ return variant;+ }++ return variant.log();+ }+}diff --git a/packages/engine-formula/src/functions/math/log/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/log/__tests__/index.spec.tsnew file mode 100644index 0000000000..0d0649a314--- /dev/null+++ b/packages/engine-formula/src/functions/math/log/__tests__/index.spec.ts@@ -0,0 +1,101 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Log } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test log function', () => {+ const testFunction = new Log(FUNCTION_NAMES_MATH.LOG);++ describe('Log', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(8);+ const base = NumberValueObject.create(2);+ const result = testFunction.calculate(number, base);+ expect(result.getValue()).toBe(3);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-2);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('1.5');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(0.17609125905568124);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const base = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, base);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });+ it('Value is blank cell', () => {+ const number = NullValueObject.create();+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });+ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, ' ', -1.575, true, 'test', 1.98, -50.55, 5],+ ]),+ rowCount: 1,+ columnCount: 8,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const base = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, 2.5, -3, -2, null],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, base);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [ErrorType.DIV_BY_ZERO, ErrorType.VALUE, ErrorType.NUM, ErrorType.NUM, ErrorType.VALUE, 0.7455022963173019, ErrorType.NUM, ErrorType.NUM, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/log/index.ts b/packages/engine-formula/src/functions/math/log/index.tsnew file mode 100644index 0000000000..0906a8b333--- /dev/null+++ b/packages/engine-formula/src/functions/math/log/index.ts@@ -0,0 +1,96 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import { expandArrayValueObject } from '../../../engine/utils/array-object';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Log extends BaseFunction {+ override minParams = 1;++ override maxParams = 2;++ override calculate(number: BaseValueObject, base?: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (base?.isError()) {+ return base;+ }++ // get max row length+ const maxRowLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getRowCount() : 1,+ base?.isArray() ? (base as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ number.isArray() ? (number as ArrayValueObject).getColumnCount() : 1,+ base?.isArray() ? (base as ArrayValueObject).getColumnCount() : 1+ );++ const numberArray = expandArrayValueObject(maxRowLength, maxColumnLength, number, ErrorValueObject.create(ErrorType.NA));+ const baseArray = base ? expandArrayValueObject(maxRowLength, maxColumnLength, base, ErrorValueObject.create(ErrorType.NA)) : [];++ const resultArray = numberArray.map((numberObject, rowIndex, columnIndex) => {+ let baseObject = base ? (baseArray as ArrayValueObject).get(rowIndex, columnIndex) as BaseValueObject : NumberValueObject.create(10);++ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ if (baseObject.isString()) {+ baseObject = baseObject.convertToNumberObjectValue();+ }++ if (baseObject.isError()) {+ return baseObject;+ }++ const numberValue = +numberObject.getValue();+ const baseValue = +baseObject.getValue();++ if (numberValue <= 0 || baseValue <= 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const baseLog = Math.log(baseValue);++ if (baseLog === 0) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const result = Math.log(numberValue) / baseLog;++ return NumberValueObject.create(result);+ });++ if ((resultArray as ArrayValueObject).getRowCount() === 1 && (resultArray as ArrayValueObject).getColumnCount() === 1) {+ return resultArray.getArrayValue()[0][0] as NumberValueObject;+ }++ return resultArray;+ }+}diff --git a/packages/engine-formula/src/functions/math/log10/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/log10/__tests__/index.spec.tsnew file mode 100644index 0000000000..3beb150cc8--- /dev/null+++ b/packages/engine-formula/src/functions/math/log10/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Log10 } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test log10 function', () => {+ const testFunction = new Log10(FUNCTION_NAMES_MATH.LOG10);++ describe('Log10', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });++ it('Value is number valid', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.17609125905568124);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0, ErrorType.VALUE, 0.08990511143939792, 0, ErrorType.NUM, ErrorType.NUM],+ [ErrorType.NUM, 2, 0.36921585741014284, ErrorType.VALUE, ErrorType.NUM, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/log10/index.ts b/packages/engine-formula/src/functions/math/log10/index.tsnew file mode 100644index 0000000000..676b4f9190--- /dev/null+++ b/packages/engine-formula/src/functions/math/log10/index.ts@@ -0,0 +1,36 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Log10 extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(variant: BaseValueObject) {+ if (variant.isString()) {+ variant = variant.convertToNumberObjectValue();+ }++ if (variant.isError()) {+ return variant;+ }++ return variant.log10();+ }+}diff --git a/packages/engine-formula/src/functions/math/mround/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/mround/__tests__/index.spec.tsnew file mode 100644index 0000000000..9329ca2881--- /dev/null+++ b/packages/engine-formula/src/functions/math/mround/__tests__/index.spec.ts@@ -0,0 +1,99 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Mround } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test mround function', () => {+ const testFunction = new Mround(FUNCTION_NAMES_MATH.MROUND);++ describe('Mround', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const multiple = NumberValueObject.create(1);+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(2);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const multiple = StringValueObject.create('1');+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(22);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const multiple = NumberValueObject.create(1);+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const multiple = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const multiple = NullValueObject.create();+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const multiple = NumberValueObject.create(1);+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, 2.149, -1.575, '21.5', 626.3, 1.98, '-50.55'],+ ]),+ rowCount: 1,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const multiple = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, -2.5, -3, null, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, multiple);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/mround/index.ts b/packages/engine-formula/src/functions/math/mround/index.tsnew file mode 100644index 0000000000..828f160ae5--- /dev/null+++ b/packages/engine-formula/src/functions/math/mround/index.ts@@ -0,0 +1,105 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { round } from '../../../engine/utils/math-kit';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';++export class Mround extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, multiple: BaseValueObject) {+ if (number.isError()) {+ return number;+ }++ if (multiple.isError()) {+ return multiple;+ }++ if (number.isArray()) {+ const rowCount = (number as ArrayValueObject).getRowCount();+ const columnCount = (number as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ number = (number as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (number.isError()) {+ return number;+ }+ }++ if (multiple.isArray()) {+ const rowCount = (multiple as ArrayValueObject).getRowCount();+ const columnCount = (multiple as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ multiple = (multiple as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (multiple.isError()) {+ return multiple;+ }+ }++ let numberValue = number.getValue();++ if (number.isNull()) {+ numberValue = 0;+ }++ if (!isRealNum(numberValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ numberValue = +numberValue;++ let multipleValue = multiple.getValue();++ if (multiple.isNull()) {+ multipleValue = 0;+ }++ if (!isRealNum(multipleValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ multipleValue = +multipleValue;++ if (multipleValue === 0) {+ return NumberValueObject.create(0);+ }++ if ((numberValue > 0 && multipleValue < 0) || (numberValue < 0 && multipleValue > 0)) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const result = round(numberValue / multipleValue, 0) * multipleValue;++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/odd/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/odd/__tests__/index.spec.tsnew file mode 100644index 0000000000..29e2b08b08--- /dev/null+++ b/packages/engine-formula/src/functions/math/odd/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Odd } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test odd function', () => {+ const testFunction = new Odd(FUNCTION_NAMES_MATH.ODD);++ describe('Odd', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(1.5);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(3);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-1);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(-1);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('3.5');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(5);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = BooleanValueObject.create(true);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(1);+ });+ it('Value is blank cell', () => {+ const number = NullValueObject.create();+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(1);+ });+ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(number);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, ' ', 5, -1.575, true, 'test', 1.98, -50.55, 5],+ [1, true, null, '2', false, -1, 2.5, -3, -2],+ ]),+ rowCount: 2,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [3, ErrorType.VALUE, 5, -3, 1, ErrorType.VALUE, 3, -51, 5],+ [1, 1, 1, 3, 1, -1, 3, -3, -3],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/odd/index.ts b/packages/engine-formula/src/functions/math/odd/index.tsnew file mode 100644index 0000000000..be546fe3fd--- /dev/null+++ b/packages/engine-formula/src/functions/math/odd/index.ts@@ -0,0 +1,78 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import { ceil } from '../../../engine/utils/math-kit';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Odd extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (number.isArray()) {+ return number.map((numberObject) => {+ if (numberObject.isError()) {+ return numberObject;+ }++ return this._handleSingleObject(numberObject);+ });+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ const numberValue = +number.getValue();++ if (!Number.isFinite(numberValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let result = numberValue < 0 ? -ceil(Math.abs(numberValue), 0) : ceil(numberValue, 0);++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (Math.abs(result) % 2 === 0) {+ numberValue < 0 ? result-- : result++;+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/pi/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/pi/__tests__/index.spec.tsnew file mode 100644index 0000000000..766a775140--- /dev/null+++ b/packages/engine-formula/src/functions/math/pi/__tests__/index.spec.ts@@ -0,0 +1,31 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Pi } from '../index';++describe('Test pi function', () => {+ const testFunction = new Pi(FUNCTION_NAMES_MATH.PI);++ describe('Pi', () => {+ it('function is normal', () => {+ const result = testFunction.calculate();+ expect(result.getValue()).toBe(3.141592653589793);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/pi/index.ts b/packages/engine-formula/src/functions/math/pi/index.tsnew file mode 100644index 0000000000..40d8e31d47--- /dev/null+++ b/packages/engine-formula/src/functions/math/pi/index.ts@@ -0,0 +1,28 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Pi extends BaseFunction {+ override minParams = 0;++ override maxParams = 0;++ override calculate() {+ return NumberValueObject.create(Math.PI);+ }+}diff --git a/packages/engine-formula/src/functions/math/radians/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/radians/__tests__/index.spec.tsnew file mode 100644index 0000000000..eab9c15e80--- /dev/null+++ b/packages/engine-formula/src/functions/math/radians/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Radians } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test radians function', () => {+ const testFunction = new Radians(FUNCTION_NAMES_MATH.RADIANS);++ describe('Radians', () => {+ it('Value is normal number', () => {+ const angle = NumberValueObject.create(270);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(4.71238898038469);+ });++ it('Value is number valid', () => {+ const angle = NumberValueObject.create(-2);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(-0.03490658503988659);+ });++ it('Value is number string', () => {+ const angle = StringValueObject.create('1.5');+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(0.026179938779914945);+ });++ it('Value is normal string', () => {+ const angle = StringValueObject.create('test');+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const angle = BooleanValueObject.create(false);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(0);+ });+ it('Value is blank cell', () => {+ const angle = NullValueObject.create();+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(0);+ });+ it('Value is error', () => {+ const angle = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(angle);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const angle = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, ' ', 5, -1.575, true, 'test'],+ [1, true, null, '2', false, -1],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(angle);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0.03752457891787808, ErrorType.VALUE, 0.08726646259971647, -0.02748893571891069, 0.017453292519943295, ErrorType.VALUE],+ [0.017453292519943295, 0.017453292519943295, 0, 0.03490658503988659, 0, -0.017453292519943295],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/radians/index.ts b/packages/engine-formula/src/functions/math/radians/index.tsnew file mode 100644index 0000000000..e28e2b099c--- /dev/null+++ b/packages/engine-formula/src/functions/math/radians/index.ts@@ -0,0 +1,73 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Radians extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(angle: BaseValueObject) {+ if (angle.isString()) {+ angle = angle.convertToNumberObjectValue();+ }++ if (angle.isError()) {+ return angle;+ }++ if (angle.isArray()) {+ return angle.map((angleObject) => {+ if (angleObject.isError()) {+ return angleObject;+ }++ return this._handleSingleObject(angleObject);+ });+ }++ return this._handleSingleObject(angle);+ }++ private _handleSingleObject(angle: BaseValueObject) {+ if (angle.isString()) {+ angle = angle.convertToNumberObjectValue();+ }++ if (angle.isError()) {+ return angle;+ }++ const angleValue = +angle.getValue();++ if (!Number.isFinite(angleValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const result = angleValue * (Math.PI / 180);++ if (Number.isNaN(result)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/rand/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/rand/__tests__/index.spec.tsnew file mode 100644index 0000000000..06274cb9b1--- /dev/null+++ b/packages/engine-formula/src/functions/math/rand/__tests__/index.spec.ts@@ -0,0 +1,33 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it, vi } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Rand } from '../index';++describe('Test rand function', () => {+ const testFunction = new Rand(FUNCTION_NAMES_MATH.RAND);++ describe('Rand', () => {+ it('function is normal', () => {+ const mockRandom = vi.spyOn(Math, 'random');+ mockRandom.mockReturnValue(0.5);+ const result = testFunction.calculate();+ expect(result.getValue()).toBe(0.5);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/rand/index.ts b/packages/engine-formula/src/functions/math/rand/index.tsnew file mode 100644index 0000000000..6326467d44--- /dev/null+++ b/packages/engine-formula/src/functions/math/rand/index.ts@@ -0,0 +1,28 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Rand extends BaseFunction {+ override minParams = 0;++ override maxParams = 0;++ override calculate() {+ return NumberValueObject.create(Math.random());+ }+}diff --git a/packages/engine-formula/src/functions/math/randarray/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/randarray/__tests__/index.spec.tsnew file mode 100644index 0000000000..4414238b96--- /dev/null+++ b/packages/engine-formula/src/functions/math/randarray/__tests__/index.spec.ts@@ -0,0 +1,125 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it, vi } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Randarray } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';++describe('Test randarray function', () => {+ const testFunction = new Randarray(FUNCTION_NAMES_MATH.RANDARRAY);++ describe('Randarray', () => {+ const mockRandom = vi.spyOn(Math, 'random');+ mockRandom.mockReturnValue(0.5);++ it('function is normal', () => {+ const result = testFunction.calculate();+ expect(result.getValue()).toBe(0.5);+ });++ it('rows is number', () => {+ const rows = NumberValueObject.create(3);+ const result = testFunction.calculate(rows);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0.5],+ [0.5],+ [0.5],+ ]);+ });++ it('rows is number, columns is number', () => {+ const rows = NumberValueObject.create(3);+ const columns = NumberValueObject.create(3);+ const result = testFunction.calculate(rows, columns);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0.5, 0.5, 0.5],+ [0.5, 0.5, 0.5],+ [0.5, 0.5, 0.5],+ ]);+ });++ it('rows or columns is 0/-2/false/blank cell', () => {+ const rows = NumberValueObject.create(0);+ const result = testFunction.calculate(rows);+ expect(result.getValue()).toBe(ErrorType.CALC);++ const rows2 = NumberValueObject.create(-2);+ const result2 = testFunction.calculate(rows2);+ expect(result2.getValue()).toBe(ErrorType.VALUE);++ const rows3 = BooleanValueObject.create(false);+ const result3 = testFunction.calculate(rows3);+ expect(result3.getValue()).toBe(ErrorType.CALC);++ const rows4 = NullValueObject.create();+ const result4 = testFunction.calculate(rows4);+ expect(result4.getValue()).toBe(ErrorType.CALC);+ });++ it('Value is array', () => {+ const rows = NumberValueObject.create(6);+ const columns = NumberValueObject.create(6);+ const min = ArrayValueObject.createByArray([+ [1],+ [2],+ ]);+ const max = ArrayValueObject.createByArray([+ [1, 2],+ [2, 3],+ ]);+ const result = testFunction.calculate(rows, columns, min, max);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [1, 1.5],+ [2, 2.5],+ ]);+ });++ it('min > max', () => {+ const rows = NumberValueObject.create(3);+ const columns = NumberValueObject.create(3);+ const min = NumberValueObject.create(3);+ const max = NumberValueObject.create(2);+ const result = testFunction.calculate(rows, columns, min, max);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('wholeNumber', () => {+ const rows = NumberValueObject.create(6);+ const columns = NumberValueObject.create(6);+ const min = ArrayValueObject.createByArray([+ [1],+ [2],+ ]);+ const max = ArrayValueObject.createByArray([+ [1, 2.5],+ [2, 3],+ ]);+ const wholeNumber = ArrayValueObject.createByArray([+ [null, 1],+ [null, null],+ ]);+ const result = testFunction.calculate(rows, columns, min, max, wholeNumber);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [1, ErrorType.VALUE],+ [2, 2.5],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/randarray/index.ts b/packages/engine-formula/src/functions/math/randarray/index.tsnew file mode 100644index 0000000000..a89c953756--- /dev/null+++ b/packages/engine-formula/src/functions/math/randarray/index.ts@@ -0,0 +1,268 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { expandArrayValueObject } from '../../../engine/utils/array-object';++export class Randarray extends BaseFunction {+ override minParams = 0;++ override maxParams = 5;++ override calculate(rows?: BaseValueObject, columns?: BaseValueObject, min?: BaseValueObject, max?: BaseValueObject, wholeNumber?: BaseValueObject) {+ if (rows?.isError()) {+ return rows;+ }++ if (columns?.isError()) {+ return columns;+ }++ if (min?.isError()) {+ return min;+ }++ if (max?.isError()) {+ return max;+ }++ if (wholeNumber?.isError()) {+ return wholeNumber;+ }++ rows = rows ?? NumberValueObject.create(1);+ columns = columns ?? NumberValueObject.create(1);+ min = min ?? NumberValueObject.create(0);+ max = max ?? NumberValueObject.create(1);+ wholeNumber = wholeNumber ?? NumberValueObject.create(0);++ // get max row length+ const maxRowLength = Math.max(+ rows?.isArray() ? (rows as ArrayValueObject).getRowCount() : 1,+ columns?.isArray() ? (columns as ArrayValueObject).getRowCount() : 1,+ min?.isArray() ? (min as ArrayValueObject).getRowCount() : 1,+ max?.isArray() ? (max as ArrayValueObject).getRowCount() : 1,+ wholeNumber?.isArray() ? (wholeNumber as ArrayValueObject).getRowCount() : 1+ );++ // get max column length+ const maxColumnLength = Math.max(+ rows?.isArray() ? (rows as ArrayValueObject).getColumnCount() : 1,+ columns?.isArray() ? (columns as ArrayValueObject).getColumnCount() : 1,+ min?.isArray() ? (min as ArrayValueObject).getColumnCount() : 1,+ max?.isArray() ? (max as ArrayValueObject).getColumnCount() : 1,+ wholeNumber?.isArray() ? (wholeNumber as ArrayValueObject).getColumnCount() : 1+ );++ if (maxRowLength === 1 && maxColumnLength === 1) {+ return this._calculateSingleCell(rows, columns, min, max, wholeNumber);+ }++ const rowsArray = expandArrayValueObject(maxRowLength, maxColumnLength, rows, ErrorValueObject.create(ErrorType.NA));+ const columnsArray = expandArrayValueObject(maxRowLength, maxColumnLength, columns, ErrorValueObject.create(ErrorType.NA));+ const minArray = expandArrayValueObject(maxRowLength, maxColumnLength, min, ErrorValueObject.create(ErrorType.NA));+ const maxArray = expandArrayValueObject(maxRowLength, maxColumnLength, max, ErrorValueObject.create(ErrorType.NA));+ const wholeNumberArray = expandArrayValueObject(maxRowLength, maxColumnLength, wholeNumber, ErrorValueObject.create(ErrorType.NA));++ return rowsArray.map((rowsObject, rowIndex, columnIndex) => {+ const columnsObject = columnsArray.get(rowIndex, columnIndex) as BaseValueObject;+ const minObject = minArray.get(rowIndex, columnIndex) as BaseValueObject;+ const maxObject = maxArray.get(rowIndex, columnIndex) as BaseValueObject;+ const wholeNumberObject = wholeNumberArray.get(rowIndex, columnIndex) as BaseValueObject;++ const _handleError = this._handleError(rowsObject, columnsObject, minObject, maxObject, wholeNumberObject);++ if (_handleError.error) {+ return _handleError.error;+ }++ let { minValue, maxValue, wholeNumberValue } = _handleError;++ let result: number;++ if (!wholeNumberValue) {+ result = Math.random() * (maxValue - minValue) + minValue;+ } else {+ minValue = Math.ceil(minValue);+ maxValue = Math.floor(maxValue);++ result = Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue;+ }++ if (result < minValue || result > maxValue) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ return NumberValueObject.create(result);+ });+ }++ private _calculateSingleCell(rows?: BaseValueObject, columns?: BaseValueObject, min?: BaseValueObject, max?: BaseValueObject, wholeNumber?: BaseValueObject) {+ if (rows?.isArray()) {+ rows = (rows as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (columns?.isArray()) {+ columns = (columns as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (min?.isArray()) {+ min = (min as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (max?.isArray()) {+ max = (max as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (wholeNumber?.isArray()) {+ wholeNumber = (wholeNumber as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ const _handleError = this._handleError(rows, columns, min, max, wholeNumber);++ if (_handleError.error) {+ return _handleError.error;+ }++ let { rowsValue, columnsValue, minValue, maxValue, wholeNumberValue } = _handleError;++ if (wholeNumberValue) {+ minValue = Math.ceil(minValue);+ maxValue = Math.floor(maxValue);++ if (minValue > maxValue) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }+ }++ const result: number[][] = [];++ for (let r = 0; r < rowsValue; r++) {+ const row: number[] = [];++ for (let c = 0; c < columnsValue; c++) {+ if (wholeNumberValue) {+ row.push(Math.floor(Math.random() * (maxValue - minValue + 1)) + minValue);+ } else {+ row.push(Math.random() * (maxValue - minValue) + minValue);+ }+ }++ result.push(row);+ }++ if (rowsValue === 1 && columnsValue === 1) {+ return NumberValueObject.create(result[0][0]);+ }++ return ArrayValueObject.createByArray(result);+ }++ private _handleError(rowsObject?: BaseValueObject, columnsObject?: BaseValueObject, minObject?: BaseValueObject, maxObject?: BaseValueObject, wholeNumberObject?: BaseValueObject) {+ if (rowsObject?.isString()) {+ rowsObject = rowsObject.convertToNumberObjectValue();+ }++ if (rowsObject?.isError()) {+ return {+ error: rowsObject,+ };+ }++ if (columnsObject?.isString()) {+ columnsObject = columnsObject.convertToNumberObjectValue();+ }++ if (columnsObject?.isError()) {+ return {+ error: columnsObject,+ };+ }++ if (minObject?.isString()) {+ minObject = minObject.convertToNumberObjectValue();+ }++ if (minObject?.isError()) {+ return {+ error: minObject,+ };+ }++ if (maxObject?.isString()) {+ maxObject = maxObject.convertToNumberObjectValue();+ }++ if (maxObject?.isError()) {+ return {+ error: maxObject,+ };+ }++ if (wholeNumberObject?.isString()) {+ wholeNumberObject = wholeNumberObject.convertToNumberObjectValue();+ }++ if (wholeNumberObject?.isError()) {+ return {+ error: wholeNumberObject,+ };+ }++ const rowsValue = rowsObject ? Math.floor(+rowsObject.getValue()) : 1;+ const columnsValue = columnsObject ? Math.floor(+columnsObject.getValue()) : 1;++ if (rowsValue === 0 || columnsValue === 0) {+ return {+ error: ErrorValueObject.create(ErrorType.CALC),+ };+ }++ if (rowsValue < 0 || columnsValue < 0) {+ return {+ error: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ const minValue = minObject ? +minObject.getValue() : 0;+ const maxValue = maxObject ? +maxObject.getValue() : 1;+ const wholeNumberValue = wholeNumberObject ? +wholeNumberObject.getValue() : 0;++ if (minValue > maxValue) {+ return {+ error: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ if (wholeNumberValue && (!Number.isInteger(minValue) || !Number.isInteger(maxValue))) {+ return {+ error: ErrorValueObject.create(ErrorType.VALUE),+ };+ }++ return {+ rowsValue,+ columnsValue,+ minValue,+ maxValue,+ wholeNumberValue,+ };+ }+}diff --git a/packages/engine-formula/src/functions/math/randbetween/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/randbetween/__tests__/index.spec.tsnew file mode 100644index 0000000000..687a6edc1b--- /dev/null+++ b/packages/engine-formula/src/functions/math/randbetween/__tests__/index.spec.ts@@ -0,0 +1,84 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it, vi } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Randbetween } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ErrorType } from '../../../../basics/error-type';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';++describe('Test randbetween function', () => {+ const testFunction = new Randbetween(FUNCTION_NAMES_MATH.RANDBETWEEN);++ describe('Randbetween', () => {+ const mockRandom = vi.spyOn(Math, 'random');+ mockRandom.mockReturnValue(0.5);++ it('Value is normal', () => {+ const bottom = NumberValueObject.create(1);+ const top = NumberValueObject.create(100);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(51);+ });++ it('bottom > top', () => {+ const bottom = NumberValueObject.create(3);+ const top = NumberValueObject.create(1);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is normal string', () => {+ const bottom = StringValueObject.create('test');+ const top = NumberValueObject.create(3);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const bottom = BooleanValueObject.create(true);+ const top = NumberValueObject.create(3);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is blank cell', () => {+ const bottom = NullValueObject.create();+ const top = NumberValueObject.create(3);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(2);+ });++ it('Value is array and rowCount or columnCount > 1', () => {+ const bottom = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ ]),+ rowCount: 1,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const top = NumberValueObject.create(3);+ const result = testFunction.calculate(bottom, top);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/randbetween/index.ts b/packages/engine-formula/src/functions/math/randbetween/index.tsnew file mode 100644index 0000000000..e76ef6fc00--- /dev/null+++ b/packages/engine-formula/src/functions/math/randbetween/index.ts@@ -0,0 +1,99 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';++export class Randbetween extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(bottom: BaseValueObject, top: BaseValueObject) {+ if (bottom.isError()) {+ return bottom;+ }++ if (top.isError()) {+ return top;+ }++ if (bottom.isArray()) {+ const rowCount = (bottom as ArrayValueObject).getRowCount();+ const columnCount = (bottom as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ bottom = (bottom as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (bottom.isError()) {+ return bottom;+ }+ }++ if (top.isArray()) {+ const rowCount = (top as ArrayValueObject).getRowCount();+ const columnCount = (top as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ top = (top as ArrayValueObject).get(0, 0) as BaseValueObject;++ if (top.isError()) {+ return top;+ }+ }++ let bottomValue = bottom.getValue();++ if (bottom.isNull()) {+ bottomValue = 0;+ }++ if (!isRealNum(bottomValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ let topValue = top.getValue();++ if (top.isNull()) {+ topValue = 0;+ }++ if (!isRealNum(topValue)) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ if (bottomValue > topValue) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ bottomValue = Math.ceil(bottomValue as number);+ topValue = Math.floor(topValue as number);++ const result = Math.floor(Math.random() * (topValue - bottomValue + 1)) + bottomValue;++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/round/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/round/__tests__/index.spec.tsnew file mode 100644index 0000000000..fac9af83ab--- /dev/null+++ b/packages/engine-formula/src/functions/math/round/__tests__/index.spec.ts@@ -0,0 +1,115 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Round } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test round function', () => {+ const testFunction = new Round(FUNCTION_NAMES_MATH.ROUND);++ describe('Round', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.2);+ });++ it('Value is normal number 2', () => {+ const number = NumberValueObject.create(2.149);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.1);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-1.475);+ const numDigits = NumberValueObject.create(2);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(-1.48);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const numDigits = StringValueObject.create('-1');+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(20);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.2);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NullValueObject.create();+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array and array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, 2.149, -1.575, '21.5', 626.3, 1.98, '-50.55'],+ ]),+ rowCount: 1,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numDigits = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, -2.5, -3, null, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, numDigits);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2.2, 2.1, -1.58, 22, 630, 0, 0, ErrorType.NA, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/round/index.ts b/packages/engine-formula/src/functions/math/round/index.tsnew file mode 100644index 0000000000..ec35d57769--- /dev/null+++ b/packages/engine-formula/src/functions/math/round/index.ts@@ -0,0 +1,45 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Round extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, numDigits: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (numDigits.isString()) {+ numDigits = numDigits.convertToNumberObjectValue();+ }++ if (numDigits.isError()) {+ return numDigits;+ }++ // Note that the order of parameters is different from JavaScript+ return number.round(numDigits);+ }+}diff --git a/packages/engine-formula/src/functions/math/rounddown/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/rounddown/__tests__/index.spec.tsnew file mode 100644index 0000000000..12cd96c865--- /dev/null+++ b/packages/engine-formula/src/functions/math/rounddown/__tests__/index.spec.ts@@ -0,0 +1,115 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Rounddown } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test rounddown function', () => {+ const testFunction = new Rounddown(FUNCTION_NAMES_MATH.ROUNDDOWN);++ describe('Rounddown', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.1);+ });++ it('Value is normal number 2', () => {+ const number = NumberValueObject.create(2.149);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.1);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-1.475);+ const numDigits = NumberValueObject.create(2);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(-1.47);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const numDigits = StringValueObject.create('-1');+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(20);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.1);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NullValueObject.create();+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array and array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, 2.149, -1.575, '21.5', 626.3, 1.98, '-50.55'],+ ]),+ rowCount: 1,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numDigits = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, -2.5, -3, null, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, numDigits);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2.1, 2.1, -1.57, 21, 620, 0, 0, ErrorType.NA, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/rounddown/index.ts b/packages/engine-formula/src/functions/math/rounddown/index.tsnew file mode 100644index 0000000000..c4271a3e77--- /dev/null+++ b/packages/engine-formula/src/functions/math/rounddown/index.ts@@ -0,0 +1,45 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Rounddown extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, numDigits: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (numDigits.isString()) {+ numDigits = numDigits.convertToNumberObjectValue();+ }++ if (numDigits.isError()) {+ return numDigits;+ }++ // Note that the order of parameters is different from JavaScript+ return number.floor(numDigits);+ }+}diff --git a/packages/engine-formula/src/functions/math/roundup/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/roundup/__tests__/index.spec.tsnew file mode 100644index 0000000000..4076f28b67--- /dev/null+++ b/packages/engine-formula/src/functions/math/roundup/__tests__/index.spec.ts@@ -0,0 +1,115 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Roundup } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test roundup function', () => {+ const testFunction = new Roundup(FUNCTION_NAMES_MATH.ROUNDUP);++ describe('Roundup', () => {+ it('Value is normal number', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.2);+ });++ it('Value is normal number 2', () => {+ const number = NumberValueObject.create(2.149);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.2);+ });++ it('Value is number valid', () => {+ const number = NumberValueObject.create(-1.475);+ const numDigits = NumberValueObject.create(2);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(-1.48);+ });++ it('Value is number string', () => {+ const number = StringValueObject.create('21.5');+ const numDigits = StringValueObject.create('-1');+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(30);+ });++ it('Value is normal string', () => {+ const number = StringValueObject.create('test');+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = BooleanValueObject.create(true);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(2.2);+ });++ it('Value is blank cell', () => {+ const number = NumberValueObject.create(2.15);+ const numDigits = NullValueObject.create();+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(3);+ });++ it('Value is error', () => {+ const number = ErrorValueObject.create(ErrorType.NAME);+ const numDigits = NumberValueObject.create(1);+ const result = testFunction.calculate(number, numDigits);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array and array', () => {+ const number = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [2.15, 2.149, -1.575, '21.5', 626.3, 1.98, '-50.55'],+ ]),+ rowCount: 1,+ columnCount: 7,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const numDigits = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, true, 2, false, -1, -2.5, -3, null, ' '],+ ]),+ rowCount: 1,+ columnCount: 9,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(number, numDigits);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [2.2, 2.2, -1.58, 22, 630, 100, -1000, ErrorType.NA, ErrorType.NA],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/roundup/index.ts b/packages/engine-formula/src/functions/math/roundup/index.tsnew file mode 100644index 0000000000..70892faffd--- /dev/null+++ b/packages/engine-formula/src/functions/math/roundup/index.ts@@ -0,0 +1,45 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Roundup extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(number: BaseValueObject, numDigits: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (numDigits.isString()) {+ numDigits = numDigits.convertToNumberObjectValue();+ }++ if (numDigits.isError()) {+ return numDigits;+ }++ // Note that the order of parameters is different from JavaScript+ return number.ceil(numDigits);+ }+}diff --git a/packages/engine-formula/src/functions/math/sec/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sec/__tests__/index.spec.tsnew file mode 100644index 0000000000..869d65fd46--- /dev/null+++ b/packages/engine-formula/src/functions/math/sec/__tests__/index.spec.ts@@ -0,0 +1,96 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sec } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test sec function', () => {+ const testFunction = new Sec(FUNCTION_NAMES_MATH.SEC);++ describe('Sec', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1.8508157176809255);+ });++ it('Value is number 2**27', () => {+ const value = NumberValueObject.create(2 ** 27);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number negative', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(-2.402997961722381);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(14.136832902969903);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1.8508157176809255);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [1.8508157176809255, ErrorType.VALUE, 2.991882480183043, 1.8508157176809255, 1, 1],+ [1, 1.1596638229046938, -1.4376836183776793, ErrorType.VALUE, -1.0101086659079939, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sec/index.ts b/packages/engine-formula/src/functions/math/sec/index.tsnew file mode 100644index 0000000000..5b5080ab12--- /dev/null+++ b/packages/engine-formula/src/functions/math/sec/index.ts@@ -0,0 +1,62 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Sec extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (number.isArray()) {+ return number.map((numberObject) => {+ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ return this._handleSingleObject(numberObject);+ });+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject) {+ const numberValue = +number.getValue();++ if (Math.abs(numberValue) >= 2 ** 27) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return number.cos().getReciprocal();+ }+}diff --git a/packages/engine-formula/src/functions/math/sech/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sech/__tests__/index.spec.tsnew file mode 100644index 0000000000..fb1f77790e--- /dev/null+++ b/packages/engine-formula/src/functions/math/sech/__tests__/index.spec.ts@@ -0,0 +1,96 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sech } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test sech function', () => {+ const testFunction = new Sech(FUNCTION_NAMES_MATH.SECH);++ describe('Sech', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.6480542736638855);+ });++ it('Value is number 2**27', () => {+ const value = NumberValueObject.create(2 ** 27);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });++ it('Value is number negative', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.2658022288340797);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.4250960349422805);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0.6480542736638855);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [0.6480542736638855, ErrorType.VALUE, 0.5385722606783082, 0.6480542736638855, 1, 1],+ [1, 7.440151952041671e-44, 0.19088406061175034, ErrorType.VALUE, 0.0993279274194332, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sech/index.ts b/packages/engine-formula/src/functions/math/sech/index.tsnew file mode 100644index 0000000000..af9e422f08--- /dev/null+++ b/packages/engine-formula/src/functions/math/sech/index.ts@@ -0,0 +1,67 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sech extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ if (number.isArray()) {+ return number.map((numberObject) => {+ if (numberObject.isString()) {+ numberObject = numberObject.convertToNumberObjectValue();+ }++ if (numberObject.isError()) {+ return numberObject;+ }++ return this._handleSingleObject(numberObject);+ });+ }++ return this._handleSingleObject(number);+ }++ private _handleSingleObject(number: BaseValueObject) {+ const numberValue = +number.getValue();++ if (!Number.isFinite(Math.cosh(numberValue))) {+ return NumberValueObject.create(0);+ }++ if (Math.abs(numberValue) >= 2 ** 27) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ return number.cosh().getReciprocal();+ }+}diff --git a/packages/engine-formula/src/functions/math/sqrt/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sqrt/__tests__/index.spec.tsnew file mode 100644index 0000000000..1b70b9476a--- /dev/null+++ b/packages/engine-formula/src/functions/math/sqrt/__tests__/index.spec.ts@@ -0,0 +1,90 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sqrt } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValue, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test sqrt function', () => {+ const testFunction = new Sqrt(FUNCTION_NAMES_MATH.SQRT);++ describe('Sqrt', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });++ it('Value is number negative', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1.224744871391589);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1);+ });+ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });+ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(transformToValue(result.getArrayValue())).toStrictEqual([+ [1, ErrorType.VALUE, 1.1090536506409416, 1, 0, 0],+ [0, 10, 1.5297058540778354, ErrorType.VALUE, ErrorType.NUM, ErrorType.NAME],+ ]);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sqrt/index.ts b/packages/engine-formula/src/functions/math/sqrt/index.tsnew file mode 100644index 0000000000..fb29d48d23--- /dev/null+++ b/packages/engine-formula/src/functions/math/sqrt/index.ts@@ -0,0 +1,36 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { BaseFunction } from '../../base-function';++export class Sqrt extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ return number.sqrt();+ }+}diff --git a/packages/engine-formula/src/functions/math/sqrtpi/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sqrtpi/__tests__/index.spec.tsnew file mode 100644index 0000000000..58f41a3635--- /dev/null+++ b/packages/engine-formula/src/functions/math/sqrtpi/__tests__/index.spec.ts@@ -0,0 +1,89 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sqrtpi } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';++describe('Test sqrtpi function', () => {+ const testFunction = new Sqrtpi(FUNCTION_NAMES_MATH.SQRTPI);++ describe('Sqrtpi', () => {+ it('Value is normal number', () => {+ const value = NumberValueObject.create(1);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1.7724538509055159);+ });++ it('Value is number negative', () => {+ const value = NumberValueObject.create(-2);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NUM);+ });++ it('Value is number string', () => {+ const value = StringValueObject.create('1.5');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(2.1708037636748028);+ });++ it('Value is normal string', () => {+ const value = StringValueObject.create('test');+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Value is boolean', () => {+ const value = BooleanValueObject.create(true);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(1.7724538509055159);+ });++ it('Value is blank cell', () => {+ const value = NullValueObject.create();+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(0);+ });++ it('Value is error', () => {+ const value = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(value);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('Value is array', () => {+ const valueArray = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, ErrorType.NAME],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(valueArray);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sqrtpi/index.ts b/packages/engine-formula/src/functions/math/sqrtpi/index.tsnew file mode 100644index 0000000000..9322f2967c--- /dev/null+++ b/packages/engine-formula/src/functions/math/sqrtpi/index.ts@@ -0,0 +1,58 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sqrtpi extends BaseFunction {+ override minParams = 1;++ override maxParams = 1;++ override calculate(number: BaseValueObject) {+ if (number.isArray()) {+ const rowCount = (number as ArrayValueObject).getRowCount();+ const columnCount = (number as ArrayValueObject).getColumnCount();++ if (rowCount > 1 || columnCount > 1) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ number = (number as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (number.isString()) {+ number = number.convertToNumberObjectValue();+ }++ if (number.isError()) {+ return number;+ }++ const numberValue = +number.getValue();++ if (numberValue < 0) {+ return ErrorValueObject.create(ErrorType.NUM);+ }++ const result = Math.sqrt(numberValue * Math.PI);++ return NumberValueObject.create(result);+ }+}diff --git a/packages/engine-formula/src/functions/math/sumsq/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sumsq/__tests__/index.spec.tsnew file mode 100644index 0000000000..f516a320ec--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumsq/__tests__/index.spec.ts@@ -0,0 +1,109 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sumsq } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { stripErrorMargin } from '../../../../engine/utils/math-kit';++describe('Test sumsq function', () => {+ const testFunction = new Sumsq(FUNCTION_NAMES_MATH.SUMSQ);++ describe('Sumsq', () => {+ it('Var1 is number, var2 is number', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = NumberValueObject.create(2);+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(5);+ });+ it('Var1 is number, var2 is string', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = StringValueObject.create('test');+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });+ it('Var1 is number, var2 is string number', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = StringValueObject.create('2');+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(5);+ });+ it('Var1 is number, var2 is boolean', () => {+ const var1 = NumberValueObject.create(2);++ let var2 = BooleanValueObject.create(true);+ let result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(5);++ var2 = BooleanValueObject.create(false);+ result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(4);+ });+ it('Var1 is number, var2 is null', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = NullValueObject.create();+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(1);+ });+ it('Var1 is number, var2 is error', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = ErrorValueObject.create(ErrorType.NA);+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(ErrorType.NA);+ });++ it('Var1 is number, var2 is array includes error', () => {+ const var1 = NumberValueObject.create(1);+ const var2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ [0, ErrorType.VALUE],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(var1, var2);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('Var1 is number, var2 is array not includes error', () => {+ const var1 = NumberValueObject.create(2);+ const var2 = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, ' ', 1.23, true, false, null],+ [0, '100', '2.34', 'test', -3, null],+ ]),+ rowCount: 2,+ columnCount: 6,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(var1, var2);+ expect(stripErrorMargin(Number(result.getValue()))).toBe(10020.9885);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sumsq/index.ts b/packages/engine-formula/src/functions/math/sumsq/index.tsnew file mode 100644index 0000000000..f0544dba08--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumsq/index.ts@@ -0,0 +1,69 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import type { BaseValueObject } from '../../../engine/value-object/base-value-object';+import { NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sumsq extends BaseFunction {+ override minParams = 1;++ override maxParams = 255;++ override calculate(...variants: BaseValueObject[]) {+ let accumulatorAll: BaseValueObject = NumberValueObject.create(0);+ const exponent = NumberValueObject.create(2);++ for (let i = 0; i < variants.length; i++) {+ let variant = variants[i];++ if (variant.isString()) {+ variant = variant.convertToNumberObjectValue();+ }++ if (variant.isError()) {+ return variant;+ }++ if (variant.isArray()) {+ (variant as ArrayValueObject).iterator((valueObject) => {+ // 'test', ' ', blank cell, TRUE and FALSE are ignored+ if (valueObject == null || valueObject.isString() || valueObject.isBoolean() || valueObject.isNull()) {+ return true; // continue+ }++ if (valueObject.isError()) {+ accumulatorAll = valueObject;+ return false; // break+ }++ accumulatorAll = (accumulatorAll as NumberValueObject).plus(+ (valueObject as BaseValueObject).pow(exponent)+ ) as BaseValueObject;+ });+ } else {+ accumulatorAll = accumulatorAll.plus(variant.pow(exponent));+ }++ if (accumulatorAll.isError()) {+ return accumulatorAll;+ }+ }++ return accumulatorAll;+ }+}diff --git a/packages/engine-formula/src/functions/math/sumx2my2/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sumx2my2/__tests__/index.spec.tsnew file mode 100644index 0000000000..c31e7ffef7--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumx2my2/__tests__/index.spec.ts@@ -0,0 +1,126 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sumx2my2 } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { stripErrorMargin } from '../../../../engine/utils/math-kit';++describe('Test sumx2my2 function', () => {+ const testFunction = new Sumx2my2(FUNCTION_NAMES_MATH.SUMX2MY2);++ describe('Sumx2my2', () => {+ it('Value is normal number', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(-3);+ });++ it('Value is number string', () => {+ const arrayX = StringValueObject.create('-3');+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(5);+ });++ it('arrayX is number, arrayY is string', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = StringValueObject.create('test');+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is bo', () => {+ const arrayX = NumberValueObject.create(1);++ let arrayY = BooleanValueObject.create(true);+ let result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);++ arrayY = BooleanValueObject.create(false);+ result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is blank cell', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NullValueObject.create();+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('arrayX is number, arrayY is error', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('arrayX.length !== arrayY.length', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ [0, ErrorType.VALUE],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NA);+ });++ it('arrayX.length === arrayY.length', () => {+ const arrayX = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ [4, 5, 6],+ ]),+ rowCount: 2,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ ['test', 2],+ [3, true],+ ]),+ rowCount: 3,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(stripErrorMargin(Number(result.getValue()))).toBe(28);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sumx2my2/index.ts b/packages/engine-formula/src/functions/math/sumx2my2/index.tsnew file mode 100644index 0000000000..ec47a0337c--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumx2my2/index.ts@@ -0,0 +1,143 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sumx2my2 extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(arrayX: BaseValueObject, arrayY: BaseValueObject) {+ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ let arrayXRowCount = 1;+ let arrayXColumnCount = 1;++ if (arrayX.isArray()) {+ arrayXRowCount = (arrayX as ArrayValueObject).getRowCount();+ arrayXColumnCount = (arrayX as ArrayValueObject).getColumnCount();+ }++ const arrayXCount = arrayXRowCount * arrayXColumnCount;++ let arrayYRowCount = 1;+ let arrayYColumnCount = 1;++ if (arrayY.isArray()) {+ arrayYRowCount = (arrayY as ArrayValueObject).getRowCount();+ arrayYColumnCount = (arrayY as ArrayValueObject).getColumnCount();+ }++ const arrayYCount = arrayYRowCount * arrayYColumnCount;++ if (arrayXCount !== arrayYCount) {+ return ErrorValueObject.create(ErrorType.NA);+ }++ if (arrayXCount === 1) {+ if (arrayX.isArray()) {+ arrayX = (arrayX as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayY.isArray()) {+ arrayY = (arrayY as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ if (arrayX.isNull() || arrayY.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const arrayXValue = +arrayX.getValue();+ const arrayYValue = +arrayY.getValue();++ if ((arrayX.isString() && !isRealNum(arrayXValue)) || arrayX.isBoolean() || (arrayY.isString() && !isRealNum(arrayYValue)) || arrayY.isBoolean()) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const result = arrayXValue ** 2 - arrayYValue ** 2;++ return NumberValueObject.create(result);+ } else {+ const arrayXFlatten = (arrayX as ArrayValueObject).flatten();+ const arrayYFlatten = (arrayY as ArrayValueObject).flatten();++ let errorObject: BaseValueObject = NullValueObject.create();+ const arrayXValidValue: number[] = [];+ const arrayYValidValue: number[] = [];+ let result: number = 0;++ arrayXFlatten.iterator((arrayXObject, rowIndex, columnIndex) => {+ const arrayYObject = arrayYFlatten.get(rowIndex, columnIndex);++ if (arrayXObject == null || arrayXObject.isString() || arrayXObject.isBoolean() || arrayXObject.isNull()) {+ return true; // continue+ }++ if (arrayXObject?.isError()) {+ errorObject = arrayXObject;+ return false; // break;+ }++ if (arrayYObject == null || arrayYObject.isString() || arrayYObject.isBoolean() || arrayYObject.isNull()) {+ return true; // continue+ }++ if (arrayYObject?.isError()) {+ errorObject = arrayYObject;+ return false; // break;+ }++ const arrayXValue = +arrayXObject.getValue();+ const arrayYValue = +arrayYObject.getValue();++ arrayXValidValue.push(arrayXValue);+ arrayYValidValue.push(arrayYValue);++ result += arrayXValue ** 2 - arrayYValue ** 2;+ });++ if (errorObject.isError()) {+ return errorObject;+ }++ if (arrayXValidValue.length === 0 || arrayYValidValue.length === 0) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ return NumberValueObject.create(result);+ }+ }+}diff --git a/packages/engine-formula/src/functions/math/sumx2py2/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sumx2py2/__tests__/index.spec.tsnew file mode 100644index 0000000000..9d1e385a9f--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumx2py2/__tests__/index.spec.ts@@ -0,0 +1,126 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sumx2py2 } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { stripErrorMargin } from '../../../../engine/utils/math-kit';++describe('Test sumx2py2 function', () => {+ const testFunction = new Sumx2py2(FUNCTION_NAMES_MATH.SUMX2PY2);++ describe('Sumx2py2', () => {+ it('Value is normal number', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(5);+ });++ it('Value is number string', () => {+ const arrayX = StringValueObject.create('-3');+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(13);+ });++ it('arrayX is number, arrayY is string', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = StringValueObject.create('test');+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is bo', () => {+ const arrayX = NumberValueObject.create(1);++ let arrayY = BooleanValueObject.create(true);+ let result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);++ arrayY = BooleanValueObject.create(false);+ result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is blank cell', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NullValueObject.create();+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('arrayX is number, arrayY is error', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('arrayX.length !== arrayY.length', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ [0, ErrorType.VALUE],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NA);+ });++ it('arrayX.length === arrayY.length', () => {+ const arrayX = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ [4, 5, 6],+ ]),+ rowCount: 2,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ ['test', 2],+ [3, true],+ ]),+ rowCount: 3,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(stripErrorMargin(Number(result.getValue()))).toBe(56);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sumx2py2/index.ts b/packages/engine-formula/src/functions/math/sumx2py2/index.tsnew file mode 100644index 0000000000..38cd8226e3--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumx2py2/index.ts@@ -0,0 +1,143 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sumx2py2 extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(arrayX: BaseValueObject, arrayY: BaseValueObject) {+ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ let arrayXRowCount = 1;+ let arrayXColumnCount = 1;++ if (arrayX.isArray()) {+ arrayXRowCount = (arrayX as ArrayValueObject).getRowCount();+ arrayXColumnCount = (arrayX as ArrayValueObject).getColumnCount();+ }++ const arrayXCount = arrayXRowCount * arrayXColumnCount;++ let arrayYRowCount = 1;+ let arrayYColumnCount = 1;++ if (arrayY.isArray()) {+ arrayYRowCount = (arrayY as ArrayValueObject).getRowCount();+ arrayYColumnCount = (arrayY as ArrayValueObject).getColumnCount();+ }++ const arrayYCount = arrayYRowCount * arrayYColumnCount;++ if (arrayXCount !== arrayYCount) {+ return ErrorValueObject.create(ErrorType.NA);+ }++ if (arrayXCount === 1) {+ if (arrayX.isArray()) {+ arrayX = (arrayX as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayY.isArray()) {+ arrayY = (arrayY as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ if (arrayX.isNull() || arrayY.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const arrayXValue = +arrayX.getValue();+ const arrayYValue = +arrayY.getValue();++ if ((arrayX.isString() && !isRealNum(arrayXValue)) || arrayX.isBoolean() || (arrayY.isString() && !isRealNum(arrayYValue)) || arrayY.isBoolean()) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const result = arrayXValue ** 2 + arrayYValue ** 2;++ return NumberValueObject.create(result);+ } else {+ const arrayXFlatten = (arrayX as ArrayValueObject).flatten();+ const arrayYFlatten = (arrayY as ArrayValueObject).flatten();++ let errorObject: BaseValueObject = NullValueObject.create();+ const arrayXValidValue: number[] = [];+ const arrayYValidValue: number[] = [];+ let result: number = 0;++ arrayXFlatten.iterator((arrayXObject, rowIndex, columnIndex) => {+ const arrayYObject = arrayYFlatten.get(rowIndex, columnIndex);++ if (arrayXObject == null || arrayXObject.isString() || arrayXObject.isBoolean() || arrayXObject.isNull()) {+ return true; // continue+ }++ if (arrayXObject?.isError()) {+ errorObject = arrayXObject;+ return false; // break;+ }++ if (arrayYObject == null || arrayYObject.isString() || arrayYObject.isBoolean() || arrayYObject.isNull()) {+ return true; // continue+ }++ if (arrayYObject?.isError()) {+ errorObject = arrayYObject;+ return false; // break;+ }++ const arrayXValue = +arrayXObject.getValue();+ const arrayYValue = +arrayYObject.getValue();++ arrayXValidValue.push(arrayXValue);+ arrayYValidValue.push(arrayYValue);++ result += arrayXValue ** 2 + arrayYValue ** 2;+ });++ if (errorObject.isError()) {+ return errorObject;+ }++ if (arrayXValidValue.length === 0 || arrayYValidValue.length === 0) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ return NumberValueObject.create(result);+ }+ }+}diff --git a/packages/engine-formula/src/functions/math/sumxmy2/__tests__/index.spec.ts b/packages/engine-formula/src/functions/math/sumxmy2/__tests__/index.spec.tsnew file mode 100644index 0000000000..b178d58764--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumxmy2/__tests__/index.spec.ts@@ -0,0 +1,126 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { describe, expect, it } from 'vitest';++import { FUNCTION_NAMES_MATH } from '../../function-names';+import { Sumxmy2 } from '../index';+import { BooleanValueObject, NullValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';+import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';+import { ErrorType } from '../../../../basics/error-type';+import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';+import { stripErrorMargin } from '../../../../engine/utils/math-kit';++describe('Test sumxmy2 function', () => {+ const testFunction = new Sumxmy2(FUNCTION_NAMES_MATH.SUMXMY2);++ describe('Sumxmy2', () => {+ it('Value is normal number', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(1);+ });++ it('Value is number string', () => {+ const arrayX = StringValueObject.create('-3');+ const arrayY = NumberValueObject.create(2);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(25);+ });++ it('arrayX is number, arrayY is string', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = StringValueObject.create('test');+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is bo', () => {+ const arrayX = NumberValueObject.create(1);++ let arrayY = BooleanValueObject.create(true);+ let result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);++ arrayY = BooleanValueObject.create(false);+ result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.DIV_BY_ZERO);+ });++ it('arrayX is number, arrayY is blank cell', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = NullValueObject.create();+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.VALUE);+ });++ it('arrayX is number, arrayY is error', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ErrorValueObject.create(ErrorType.NAME);+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NAME);+ });++ it('arrayX.length !== arrayY.length', () => {+ const arrayX = NumberValueObject.create(1);+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ [0, ErrorType.VALUE],+ ]),+ rowCount: 2,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(result.getValue()).toBe(ErrorType.NA);+ });++ it('arrayX.length === arrayY.length', () => {+ const arrayX = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, 2, 3],+ [4, 5, 6],+ ]),+ rowCount: 2,+ columnCount: 3,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const arrayY = ArrayValueObject.create({+ calculateValueList: transformToValueObject([+ [1, null],+ ['test', 2],+ [3, true],+ ]),+ rowCount: 3,+ columnCount: 2,+ unitId: '',+ sheetId: '',+ row: 0,+ column: 0,+ });+ const result = testFunction.calculate(arrayX, arrayY);+ expect(stripErrorMargin(Number(result.getValue()))).toBe(8);+ });+ });+});diff --git a/packages/engine-formula/src/functions/math/sumxmy2/index.ts b/packages/engine-formula/src/functions/math/sumxmy2/index.tsnew file mode 100644index 0000000000..b6881b25f1--- /dev/null+++ b/packages/engine-formula/src/functions/math/sumxmy2/index.ts@@ -0,0 +1,143 @@+/**+ * Copyright 2023-present DreamNum Inc.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { isRealNum } from '@univerjs/core';+import { ErrorType } from '../../../basics/error-type';+import type { ArrayValueObject } from '../../../engine/value-object/array-value-object';+import { type BaseValueObject, ErrorValueObject } from '../../../engine/value-object/base-value-object';+import { NullValueObject, NumberValueObject } from '../../../engine/value-object/primitive-object';+import { BaseFunction } from '../../base-function';++export class Sumxmy2 extends BaseFunction {+ override minParams = 2;++ override maxParams = 2;++ override calculate(arrayX: BaseValueObject, arrayY: BaseValueObject) {+ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ let arrayXRowCount = 1;+ let arrayXColumnCount = 1;++ if (arrayX.isArray()) {+ arrayXRowCount = (arrayX as ArrayValueObject).getRowCount();+ arrayXColumnCount = (arrayX as ArrayValueObject).getColumnCount();+ }++ const arrayXCount = arrayXRowCount * arrayXColumnCount;++ let arrayYRowCount = 1;+ let arrayYColumnCount = 1;++ if (arrayY.isArray()) {+ arrayYRowCount = (arrayY as ArrayValueObject).getRowCount();+ arrayYColumnCount = (arrayY as ArrayValueObject).getColumnCount();+ }++ const arrayYCount = arrayYRowCount * arrayYColumnCount;++ if (arrayXCount !== arrayYCount) {+ return ErrorValueObject.create(ErrorType.NA);+ }++ if (arrayXCount === 1) {+ if (arrayX.isArray()) {+ arrayX = (arrayX as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayY.isArray()) {+ arrayY = (arrayY as ArrayValueObject).get(0, 0) as BaseValueObject;+ }++ if (arrayX.isError()) {+ return arrayX;+ }++ if (arrayY.isError()) {+ return arrayY;+ }++ if (arrayX.isNull() || arrayY.isNull()) {+ return ErrorValueObject.create(ErrorType.VALUE);+ }++ const arrayXValue = +arrayX.getValue();+ const arrayYValue = +arrayY.getValue();++ if ((arrayX.isString() && !isRealNum(arrayXValue)) || arrayX.isBoolean() || (arrayY.isString() && !isRealNum(arrayYValue)) || arrayY.isBoolean()) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ const result = (arrayXValue - arrayYValue) ** 2;++ return NumberValueObject.create(result);+ } else {+ const arrayXFlatten = (arrayX as ArrayValueObject).flatten();+ const arrayYFlatten = (arrayY as ArrayValueObject).flatten();++ let errorObject: BaseValueObject = NullValueObject.create();+ const arrayXValidValue: number[] = [];+ const arrayYValidValue: number[] = [];+ let result: number = 0;++ arrayXFlatten.iterator((arrayXObject, rowIndex, columnIndex) => {+ const arrayYObject = arrayYFlatten.get(rowIndex, columnIndex);++ if (arrayXObject == null || arrayXObject.isString() || arrayXObject.isBoolean() || arrayXObject.isNull()) {+ return true; // continue+ }++ if (arrayXObject?.isError()) {+ errorObject = arrayXObject;+ return false; // break;+ }++ if (arrayYObject == null || arrayYObject.isString() || arrayYObject.isBoolean() || arrayYObject.isNull()) {+ return true; // continue+ }++ if (arrayYObject?.isError()) {+ errorObject = arrayYObject;+ return false; // break;+ }++ const arrayXValue = +arrayXObject.getValue();+ const arrayYValue = +arrayYObject.getValue();++ arrayXValidValue.push(arrayXValue);+ arrayYValidValue.push(arrayYValue);++ result += (arrayXValue - arrayYValue) ** 2;+ });++ if (errorObject.isError()) {+ return errorObject;+ }++ if (arrayXValidValue.length === 0 || arrayYValidValue.length === 0) {+ return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);+ }++ return NumberValueObject.create(result);+ }+ }+}diff --git a/packages/sheets-formula/src/locale/function-list/math/en-US.ts b/packages/sheets-formula/src/locale/function-list/math/en-US.tsindex fff49711ea..24d9782df1 100644--- a/packages/sheets-formula/src/locale/function-list/math/en-US.ts+++ b/packages/sheets-formula/src/locale/function-list/math/en-US.ts@@ -202,8 +202,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },},},CEILING_MATH: {@@ -216,8 +216,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },+ mode: { name: 'mode', detail: 'For negative numbers, controls whether Number is rounded toward or away from zero.' },},},CEILING_PRECISE: {@@ -230,8 +231,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },},},COMBIN: {@@ -350,8 +351,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: 'text', detail: 'The string length of Text must be less than or equal to 255 characters.' },+ radix: { name: 'radix', detail: 'The base radix that you want to convert the number into. Must be an integer greater than or equal to 2 and less than or equal to 36.' },},},DEGREES: {@@ -364,8 +365,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: 'angle', detail: 'The angle in radians that you want to convert.' },},},EVEN: {@@ -378,8 +378,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value to round.' },},},EXP: {@@ -392,8 +391,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The exponent applied to the base e.' },},},FACT: {@@ -434,8 +432,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },},},FLOOR_MATH: {@@ -448,8 +446,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },+ mode: { name: 'mode', detail: 'For negative numbers, controls whether Number is rounded toward or away from zero.' },},},FLOOR_PRECISE: {@@ -462,8 +461,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value you want to round.' },+ significance: { name: 'significance', detail: 'The multiple to which you want to round.' },},},GCD: {@@ -546,8 +545,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The positive real number for which you want the natural logarithm.' },},},LOG: {@@ -560,8 +558,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The positive real number for which you want the logarithm.' },+ base: { name: 'base', detail: 'The base of the logarithm. If base is omitted, it is assumed to be 10.' },},},LOG10: {@@ -574,8 +572,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The positive real number for which you want the base-10 logarithm.' },},},MDETERM: {@@ -644,8 +641,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value to round.' },+ multiple: { name: 'multiple', detail: 'The multiple to which you want to round number.' },},},MULTINOMIAL: {@@ -686,8 +683,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The value to round.' },},},PI: {@@ -700,8 +696,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},POWER: {@@ -756,8 +750,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: 'angle', detail: 'An angle in degrees that you want to convert.' },},},RAND: {@@ -770,8 +763,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},RANDARRAY: {@@ -784,8 +775,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ rows: { name: 'rows', detail: 'The number of rows to be returned' },+ columns: { name: 'columns', detail: 'The number of columns to be returned' },+ min: { name: 'min', detail: 'The minimum number you would like returned' },+ max: { name: 'max', detail: 'The maximum number you would like returned' },+ wholeNumber: { name: 'whole_number', detail: 'Return a whole number or a decimal value' },},},RANDBETWEEN: {@@ -798,8 +792,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ bottom: { name: 'bottom', detail: 'The smallest integer RANDBETWEEN will return.' },+ top: { name: 'top', detail: 'The largest integer RANDBETWEEN will return.' },},},ROMAN: {@@ -826,8 +820,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number that you want to round.' },+ numDigits: { name: 'num_digits', detail: 'The number of digits to which you want to round the number argument.' },},},ROUNDDOWN: {@@ -840,8 +834,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number that you want to round.' },+ numDigits: { name: 'num_digits', detail: 'The number of digits to which you want to round the number argument.' },},},ROUNDUP: {@@ -854,8 +848,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number that you want to round.' },+ numDigits: { name: 'num_digits', detail: 'The number of digits to which you want to round the number argument.' },},},SEC: {@@ -868,8 +862,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'Number is the angle in radians for which you want the secant.' },},},SECH: {@@ -882,8 +875,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'Number is the angle in radians for which you want the hyperbolic secant.' },},},SERIESSUM: {@@ -964,8 +956,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number for which you want the square root.' },},},SQRTPI: {@@ -978,8 +969,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: 'number', detail: 'The number by which pi is multiplied.' },},},SUBTOTAL: {@@ -1082,8 +1072,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number1: { name: 'number1', detail: 'To square and find the first number, you can also use a single array or a reference to an array instead of comma-separated parameters.' },+ number2: { name: 'number2', detail: 'The second number to be squared and summed. Up to 255 numbers can be specified in this way.' },},},SUMX2MY2: {@@ -1096,8 +1086,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: 'array_x', detail: 'The first array or range of values.' },+ arrayY: { name: 'array_y', detail: 'The second array or range of values.' },},},SUMX2PY2: {@@ -1110,8 +1100,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: 'array_x', detail: 'The first array or range of values.' },+ arrayY: { name: 'array_y', detail: 'The second array or range of values.' },},},SUMXMY2: {@@ -1124,8 +1114,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: 'array_x', detail: 'The first array or range of values.' },+ arrayY: { name: 'array_y', detail: 'The second array or range of values.' },},},TAN: {diff --git a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts b/packages/sheets-formula/src/locale/function-list/math/ja-JP.tsindex 8a94541651..71e60621af 100644--- a/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts+++ b/packages/sheets-formula/src/locale/function-list/math/ja-JP.ts@@ -202,8 +202,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },},},CEILING_MATH: {@@ -216,8 +216,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },+ mode: { name: 'モード', detail: '負の数値の場合、数値を 0 に丸めるか、ゼロから遠ざけるかを制御します。' },},},CEILING_PRECISE: {@@ -230,8 +231,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },},},COMBIN: {@@ -350,8 +351,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '文字列', detail: '文字列の長さは 255 文字以下にする必要があります。' },+ radix: { name: '基数', detail: ' 数値を変換する基数 (底) の数値を指定します。 2 以上、36 以下の整数である必要があります。' },},},DEGREES: {@@ -364,8 +365,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: '度に変換するラジアン単位の角度を指定します。' },},},EVEN: {@@ -378,8 +378,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },},},EXP: {@@ -392,8 +391,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: 'e を底とするべき乗の指数を指定します。' },},},FACT: {@@ -434,8 +432,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },},},FLOOR_MATH: {@@ -448,8 +446,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },+ mode: { name: 'モード', detail: '負の数値の場合、数値を 0 に丸めるか、ゼロから遠ざけるかを制御します。' },},},FLOOR_PRECISE: {@@ -462,8 +461,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ significance: { name: '基準値', detail: '倍数の基準となる数値を指定します。' },},},GCD: {@@ -546,8 +545,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '自然対数を求める正の実数を指定します。' },},},LOG: {@@ -560,8 +558,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '対数を求める正の実数を指定します。' },+ base: { name: '底', detail: '対数の底を指定します。 底を省略すると、10 を指定したと見なされます。' },},},LOG10: {@@ -574,8 +572,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '10 を底とする対数 (常用対数) を求める正の実数を指定します。' },},},MDETERM: {@@ -644,8 +641,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },+ multiple: { name: '複数', detail: '数値を丸める倍数。' },},},MULTINOMIAL: {@@ -686,8 +683,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '丸めの対象となる数値を指定します。' },},},PI: {@@ -700,8 +696,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},POWER: {@@ -756,8 +750,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: 'ラジアンに変換する角度を指定します。' },},},RAND: {@@ -770,8 +763,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},RANDARRAY: {@@ -784,8 +775,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ rows: { name: '行の数', detail: '返される行の数' },+ columns: { name: '列の数', detail: '返される列の数' },+ min: { name: '最小値', detail: '返される最小値' },+ max: { name: '最大値', detail: '返される最大値' },+ wholeNumber: { name: '整数', detail: '整数または 10 進数の値のどちらを返すのかを指定' },},},RANDBETWEEN: {@@ -798,8 +792,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ bottom: { name: '最小値', detail: ' 乱数の最小値を整数で指定します。' },+ top: { name: '最大値', detail: '乱数の最大値を整数で指定します。' },},},ROMAN: {@@ -826,8 +820,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '四捨五入の対象となる数値を指定します。' },+ numDigits: { name: '桁数', detail: '数値を四捨五入した結果の桁数を指定します。' },},},ROUNDDOWN: {@@ -840,8 +834,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '四捨五入の対象となる数値を指定します。' },+ numDigits: { name: '桁数', detail: '数値を四捨五入した結果の桁数を指定します。' },},},ROUNDUP: {@@ -854,8 +848,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '四捨五入の対象となる数値を指定します。' },+ numDigits: { name: '桁数', detail: '数値を四捨五入した結果の桁数を指定します。' },},},SEC: {@@ -868,8 +862,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '数値は、セカントが必要なラジアンの角度です。' },},},SECH: {@@ -882,8 +875,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '数値は、双曲線のセカントが必要なラジアンの角度です。' },},},SERIESSUM: {@@ -964,8 +956,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: '平方根を求める数値を指定します。' },},},SQRTPI: {@@ -978,8 +969,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数値', detail: 'π倍する数値を指定します。' },},},SUBTOTAL: {@@ -1073,8 +1063,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number1: { name: '数値1', detail: '最初の数値を二乗して合計するには、コンマ区切りの引数の代わりに単一の配列または配列への参照を使用することもできます。' },+ number2: { name: '数値2', detail: '二乗を合計する 2 番目の数値。この方法では、最大 255 個の番号を指定できます。' },},},SUMX2MY2: {@@ -1087,8 +1077,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '配列1', detail: '対象となる一方の数値配列またはセル範囲を指定します。' },+ arrayY: { name: '配列2', detail: '対象となるもう一方の数値配列またはセル範囲を指定します。' },},},SUMX2PY2: {@@ -1101,8 +1091,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '配列1', detail: '対象となる一方の数値配列またはセル範囲を指定します。' },+ arrayY: { name: '配列2', detail: '対象となるもう一方の数値配列またはセル範囲を指定します。' },},},SUMXMY2: {@@ -1115,8 +1105,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '配列1', detail: '対象となる一方の数値配列またはセル範囲を指定します。' },+ arrayY: { name: '配列2', detail: '対象となるもう一方の数値配列またはセル範囲を指定します。' },},},TAN: {diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts b/packages/sheets-formula/src/locale/function-list/math/zh-CN.tsindex 6a8c306edf..f2e9d7656c 100644--- a/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts+++ b/packages/sheets-formula/src/locale/function-list/math/zh-CN.ts@@ -201,8 +201,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },},},CEILING_MATH: {@@ -215,8 +215,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },+ mode: { name: '众数', detail: '对于负数,控制数值是舍入为零还是从零舍入。' },},},CEILING_PRECISE: {@@ -229,8 +230,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },},},COMBIN: {@@ -349,8 +350,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '字符串', detail: '字符串长度必须小于或等于 255 个字符。' },+ radix: { name: '基数', detail: '要将数字转换为的基数。 必须是大于或等于 2 且小于或等于 36 的整数。' },},},DEGREES: {@@ -363,8 +364,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: '要转换的角度,以弧度表示。' },},},EVEN: {@@ -377,8 +377,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },},},EXP: {@@ -391,8 +390,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '底数 e 的指数。' },},},FACT: {@@ -433,8 +431,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },},},FLOOR_MATH: {@@ -447,8 +445,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },+ mode: { name: '众数', detail: '对于负数,控制数值是舍入为零还是从零舍入。' },},},FLOOR_PRECISE: {@@ -461,8 +460,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },+ significance: { name: '倍数', detail: '要舍入到的倍数。' },},},GCD: {@@ -545,8 +544,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '想要计算其自然对数的正实数。' },},},LOG: {@@ -559,8 +557,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '想要计算其对数的正实数。' },+ base: { name: '底数', detail: '对数的底数。 如果省略 base,则假定其值为 10。' },},},LOG10: {@@ -573,8 +571,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '想要计算其以 10 为底的对数的正实数。' },},},MDETERM: {@@ -643,8 +640,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要四舍五入的数字。' },+ multiple: { name: '倍数', detail: '要舍入到的倍数。' },},},MULTINOMIAL: {@@ -685,8 +682,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要舍入的值。' },},},PI: {@@ -699,8 +695,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},POWER: {@@ -755,8 +749,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: '要转换的以度数表示的角度。' },},},RAND: {@@ -769,8 +762,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},RANDARRAY: {@@ -785,8 +776,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ rows: { name: '行数', detail: '要返回的行数' },+ columns: { name: '列数', detail: '要返回的列数' },+ min: { name: '最小值', detail: '想返回的最小数值' },+ max: { name: '最大值', detail: '想返回的最大数值' },+ wholeNumber: { name: '整数', detail: '返回整数或十进制值' },},},RANDBETWEEN: {@@ -799,8 +793,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ bottom: { name: '最小值', detail: '将返回的最小整数。' },+ top: { name: '最大值', detail: '将返回的最大整数。' },},},ROMAN: {@@ -827,8 +821,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要四舍五入的数字。' },+ numDigits: { name: '位数', detail: '要进行四舍五入运算的位数。' },},},ROUNDDOWN: {@@ -841,8 +835,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要四舍五入的数字。' },+ numDigits: { name: '位数', detail: '要进行四舍五入运算的位数。' },},},ROUNDUP: {@@ -855,8 +849,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要四舍五入的数字。' },+ numDigits: { name: '位数', detail: '要进行四舍五入运算的位数。' },},},SEC: {@@ -869,13 +863,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '数值是需要其正割值的角度(以弧度为单位)。' },},},SECH: {- description: '返回角度的双曲正切值',- abstract: '返回角度的双曲正切值',+ description: '返回角度的双曲正割值',+ abstract: '返回角度的双曲正割值',links: [{title: '教学',@@ -883,8 +876,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '数值是需要其双曲正割值的角度(以弧度为单位)。' },},},SERIESSUM: {@@ -965,8 +957,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '要计算其平方根的数字。' },},},SQRTPI: {@@ -979,8 +970,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '数值', detail: '与 pi 相乘的数。' },},},SUBTOTAL: {@@ -1083,8 +1073,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number1: { name: '数值1', detail: '要对其求平方和第1个数字,也可以用单一数组或对某个数组的引用来代替用逗号分隔的参数。' },+ number2: { name: '数值2', detail: '要对其求平方和的第2个数字。可以按照这种方式最多指定255个数字。' },},},SUMX2MY2: {@@ -1097,8 +1087,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '数组1', detail: '第一个数组或数值区域。' },+ arrayY: { name: '数组2', detail: '第二个数组或数值区域。' },},},SUMX2PY2: {@@ -1111,8 +1101,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '数组1', detail: '第一个数组或数值区域。' },+ arrayY: { name: '数组2', detail: '第二个数组或数值区域。' },},},SUMXMY2: {@@ -1125,8 +1115,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '数组1', detail: '第一个数组或数值区域。' },+ arrayY: { name: '数组2', detail: '第二个数组或数值区域。' },},},TAN: {diff --git a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts b/packages/sheets-formula/src/locale/function-list/math/zh-TW.tsindex f5a7b2a113..19f4e34deb 100644--- a/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts+++ b/packages/sheets-formula/src/locale/function-list/math/zh-TW.ts@@ -191,8 +191,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要轉換的數位。 必須是大於或等於 0 且小於 2^53 的整數。' },+ radix: { name: '基數', detail: '這是要將數字轉換為底數的基數。 必須是大於或等於 2 且小於或等於 36 的整數。' },},},CEILING: {@@ -205,8 +205,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },},},CEILING_MATH: {@@ -219,8 +219,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },+ mode: { name: '眾數', detail: '對於負數,請控制數位是否趨於或背離於零。' },},},CEILING_PRECISE: {@@ -233,8 +234,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },},},COMBIN: {@@ -358,8 +359,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ text: { name: '字串', detail: '字串長度必須小於或等於 255 個字元。' },+ radix: { name: '基數', detail: '這是要將數字轉換為底數的基數。 必須是大於或等於 2 且小於或等於 36 的整數。' },},},DEGREES: {@@ -372,8 +373,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: '這是要轉換的角度,以弧度表示。' },},},EVEN: {@@ -386,8 +386,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨入的數值。' },},},EXP: {@@ -400,8 +399,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是套用至基數 e 的指數。' },},},FACT: {@@ -442,8 +440,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },},},FLOOR_MATH: {@@ -456,8 +454,9 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },+ mode: { name: '眾數', detail: '對於負數,請控制數位是否趨於或背離於零。' },},},FLOOR_PRECISE: {@@ -470,8 +469,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨位的數值。' },+ significance: { name: '倍數', detail: '這是要捨位的倍數。' },},},GCD: {@@ -554,8 +553,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要求得自然對數的正實數。' },},},LOG: {@@ -568,8 +566,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要求得對數的正實數。' },+ base: { name: '底數', detail: '這是對數的底數。 如果省略 base,則假設其值為 10。' },},},LOG10: {@@ -582,8 +580,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要求得底數為 10 之對數的正實數。' },},},MDETERM: {@@ -652,8 +649,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨入的數值。' },+ multiple: { name: '倍數', detail: '這是要捨入數字的倍數。' },},},MULTINOMIAL: {@@ -694,8 +691,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要捨入的數值。' },},},PI: {@@ -708,8 +704,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},POWER: {@@ -763,8 +757,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ angle: { name: '角度', detail: '這是要轉換的角度 (以度數為單位)。' },},},RAND: {@@ -777,8 +770,6 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },},},RANDARRAY: {@@ -793,8 +784,11 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ rows: { name: '列數', detail: '要傳回的列數' },+ columns: { name: '欄數', detail: '要傳回的欄數' },+ min: { name: '最小值', detail: '想要傳回的最小數字' },+ max: { name: '最大值', detail: '想要傳回的最大數字' },+ wholeNumber: { name: '整數', detail: '傳回整數或小數數值' },},},RANDBETWEEN: {@@ -807,8 +801,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ bottom: { name: '最小值', detail: '會傳回的最小整數。' },+ top: { name: '最大值', detail: '會傳回的最大整數。' },},},ROMAN: {@@ -835,8 +829,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要四捨五入的數字。' },+ numDigits: { name: '位數', detail: '這是要對數字引數進位的位數。' },},},ROUNDDOWN: {@@ -849,8 +843,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要四捨五入的數字。' },+ numDigits: { name: '位數', detail: '這是要對數字引數進位的位數。' },},},ROUNDUP: {@@ -863,8 +857,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要四捨五入的數字。' },+ numDigits: { name: '位數', detail: '這是要對數字引數進位的位數。' },},},SEC: {@@ -877,13 +871,12 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '數值是要求得正割值的角度,以弧度表示。' },},},SECH: {- description: '返回角度的雙曲正切值',- abstract: '返回角度的雙曲正切值',+ description: '返回角度的雙曲正割值',+ abstract: '返回角度的雙曲正割值',links: [{title: '教導',@@ -891,8 +884,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '數值是要求得雙曲正割值的角度,以弧度表示。' },},},SERIESSUM: {@@ -975,8 +967,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要求得平方根的數字。' },},},SQRTPI: {@@ -989,8 +980,7 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number: { name: '數值', detail: '這是要乘以 pi 的數值。' },},},SUBTOTAL: {@@ -1093,8 +1083,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ number1: { name: '數值1', detail: '這是要求出平方總和的第1個數字。您也可以使用單一陣列或陣列參照來取代以逗點分隔的引數。' },+ number2: { name: '數值2', detail: '這是要求出平方總和的第2個數字。可以按照這種方式指定最多 255 個數字。' },},},SUMX2MY2: {@@ -1107,8 +1097,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '值陣列1', detail: '這是第一個值陣列或範圍。' },+ arrayY: { name: '值陣列2', detail: '這是第二個值陣列或範圍。' },},},SUMX2PY2: {@@ -1121,8 +1111,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '值陣列1', detail: '這是第一個值陣列或範圍。' },+ arrayY: { name: '值陣列2', detail: '這是第二個值陣列或範圍。' },},},SUMXMY2: {@@ -1135,8 +1125,8 @@ export default {},],functionParameter: {- number1: { name: 'number1', detail: 'first' },- number2: { name: 'number2', detail: 'second' },+ arrayX: { name: '值陣列1', detail: '這是第一個值陣列或範圍。' },+ arrayY: { name: '值陣列2', detail: '這是第二個值陣列或範圍。' },},},TAN: {diff --git a/packages/sheets-formula/src/services/function-list/math.ts b/packages/sheets-formula/src/services/function-list/math.tsindex a5b8e98b7e..f47c111855 100644--- a/packages/sheets-formula/src/services/function-list/math.ts+++ b/packages/sheets-formula/src/services/function-list/math.ts@@ -255,16 +255,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.CEILING.abstract',functionParameter: [{- name: 'formula.functionList.CEILING.functionParameter.number1.name',- detail: 'formula.functionList.CEILING.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.CEILING.functionParameter.number.name',+ detail: 'formula.functionList.CEILING.functionParameter.number.detail',+ example: '2.5',require: 1,repeat: 0,},{- name: 'formula.functionList.CEILING.functionParameter.number2.name',- detail: 'formula.functionList.CEILING.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.CEILING.functionParameter.significance.name',+ detail: 'formula.functionList.CEILING.functionParameter.significance.detail',+ example: '1',require: 1,repeat: 0,},@@ -277,17 +277,24 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.CEILING_MATH.abstract',functionParameter: [{- name: 'formula.functionList.CEILING_MATH.functionParameter.number1.name',- detail: 'formula.functionList.CEILING_MATH.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.CEILING_MATH.functionParameter.number.name',+ detail: 'formula.functionList.CEILING_MATH.functionParameter.number.detail',+ example: '-5.5',require: 1,repeat: 0,},{- name: 'formula.functionList.CEILING_MATH.functionParameter.number2.name',- detail: 'formula.functionList.CEILING_MATH.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.CEILING_MATH.functionParameter.significance.name',+ detail: 'formula.functionList.CEILING_MATH.functionParameter.significance.detail',+ example: '2',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.CEILING_MATH.functionParameter.mode.name',+ detail: 'formula.functionList.CEILING_MATH.functionParameter.mode.detail',+ example: '-1',+ require: 0,repeat: 0,},],@@ -299,17 +306,17 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.CEILING_PRECISE.abstract',functionParameter: [{- name: 'formula.functionList.CEILING_PRECISE.functionParameter.number1.name',- detail: 'formula.functionList.CEILING_PRECISE.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.CEILING_PRECISE.functionParameter.number.name',+ detail: 'formula.functionList.CEILING_PRECISE.functionParameter.number.detail',+ example: '4.3',require: 1,repeat: 0,},{- name: 'formula.functionList.CEILING_PRECISE.functionParameter.number2.name',- detail: 'formula.functionList.CEILING_PRECISE.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.CEILING_PRECISE.functionParameter.significance.name',+ detail: 'formula.functionList.CEILING_PRECISE.functionParameter.significance.detail',+ example: '2',+ require: 0,repeat: 0,},],@@ -455,16 +462,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.DECIMAL.abstract',functionParameter: [{- name: 'formula.functionList.DECIMAL.functionParameter.number1.name',- detail: 'formula.functionList.DECIMAL.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.DECIMAL.functionParameter.text.name',+ detail: 'formula.functionList.DECIMAL.functionParameter.text.detail',+ example: '"FF"',require: 1,repeat: 0,},{- name: 'formula.functionList.DECIMAL.functionParameter.number2.name',- detail: 'formula.functionList.DECIMAL.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.DECIMAL.functionParameter.radix.name',+ detail: 'formula.functionList.DECIMAL.functionParameter.radix.detail',+ example: '16',require: 1,repeat: 0,},@@ -477,16 +484,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.DEGREES.abstract',functionParameter: [{- name: 'formula.functionList.DEGREES.functionParameter.number1.name',- detail: 'formula.functionList.DEGREES.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.DEGREES.functionParameter.number2.name',- detail: 'formula.functionList.DEGREES.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.DEGREES.functionParameter.angle.name',+ detail: 'formula.functionList.DEGREES.functionParameter.angle.detail',+ example: 'PI()',require: 1,repeat: 0,},@@ -499,16 +499,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.EVEN.abstract',functionParameter: [{- name: 'formula.functionList.EVEN.functionParameter.number1.name',- detail: 'formula.functionList.EVEN.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.EVEN.functionParameter.number2.name',- detail: 'formula.functionList.EVEN.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.EVEN.functionParameter.number.name',+ detail: 'formula.functionList.EVEN.functionParameter.number.detail',+ example: '1.5',require: 1,repeat: 0,},@@ -521,16 +514,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.EXP.abstract',functionParameter: [{- name: 'formula.functionList.EXP.functionParameter.number1.name',- detail: 'formula.functionList.EXP.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.EXP.functionParameter.number2.name',- detail: 'formula.functionList.EXP.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.EXP.functionParameter.number.name',+ detail: 'formula.functionList.EXP.functionParameter.number.detail',+ example: '2',require: 1,repeat: 0,},@@ -587,16 +573,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.FLOOR.abstract',functionParameter: [{- name: 'formula.functionList.FLOOR.functionParameter.number1.name',- detail: 'formula.functionList.FLOOR.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.FLOOR.functionParameter.number.name',+ detail: 'formula.functionList.FLOOR.functionParameter.number.detail',+ example: '3.7',require: 1,repeat: 0,},{- name: 'formula.functionList.FLOOR.functionParameter.number2.name',- detail: 'formula.functionList.FLOOR.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.FLOOR.functionParameter.significance.name',+ detail: 'formula.functionList.FLOOR.functionParameter.significance.detail',+ example: '2',require: 1,repeat: 0,},@@ -609,17 +595,24 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.FLOOR_MATH.abstract',functionParameter: [{- name: 'formula.functionList.FLOOR_MATH.functionParameter.number1.name',- detail: 'formula.functionList.FLOOR_MATH.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.FLOOR_MATH.functionParameter.number.name',+ detail: 'formula.functionList.FLOOR_MATH.functionParameter.number.detail',+ example: '-5.5',require: 1,repeat: 0,},{- name: 'formula.functionList.FLOOR_MATH.functionParameter.number2.name',- detail: 'formula.functionList.FLOOR_MATH.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.FLOOR_MATH.functionParameter.significance.name',+ detail: 'formula.functionList.FLOOR_MATH.functionParameter.significance.detail',+ example: '2',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.FLOOR_MATH.functionParameter.mode.name',+ detail: 'formula.functionList.FLOOR_MATH.functionParameter.mode.detail',+ example: '-1',+ require: 0,repeat: 0,},],@@ -631,17 +624,17 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.FLOOR_PRECISE.abstract',functionParameter: [{- name: 'formula.functionList.FLOOR_PRECISE.functionParameter.number1.name',- detail: 'formula.functionList.FLOOR_PRECISE.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.FLOOR_PRECISE.functionParameter.number.name',+ detail: 'formula.functionList.FLOOR_PRECISE.functionParameter.number.detail',+ example: '-3.2',require: 1,repeat: 0,},{- name: 'formula.functionList.FLOOR_PRECISE.functionParameter.number2.name',- detail: 'formula.functionList.FLOOR_PRECISE.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.FLOOR_PRECISE.functionParameter.significance.name',+ detail: 'formula.functionList.FLOOR_PRECISE.functionParameter.significance.detail',+ example: '-1',+ require: 0,repeat: 0,},],@@ -763,16 +756,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.LN.abstract',functionParameter: [{- name: 'formula.functionList.LN.functionParameter.number1.name',- detail: 'formula.functionList.LN.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.LN.functionParameter.number2.name',- detail: 'formula.functionList.LN.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.LN.functionParameter.number.name',+ detail: 'formula.functionList.LN.functionParameter.number.detail',+ example: 'EXP(3)',require: 1,repeat: 0,},@@ -785,17 +771,17 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.LOG.abstract',functionParameter: [{- name: 'formula.functionList.LOG.functionParameter.number1.name',- detail: 'formula.functionList.LOG.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.LOG.functionParameter.number.name',+ detail: 'formula.functionList.LOG.functionParameter.number.detail',+ example: '8',require: 1,repeat: 0,},{- name: 'formula.functionList.LOG.functionParameter.number2.name',- detail: 'formula.functionList.LOG.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.LOG.functionParameter.base.name',+ detail: 'formula.functionList.LOG.functionParameter.base.detail',+ example: '2',+ require: 0,repeat: 0,},],@@ -807,16 +793,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.LOG10.abstract',functionParameter: [{- name: 'formula.functionList.LOG10.functionParameter.number1.name',- detail: 'formula.functionList.LOG10.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.LOG10.functionParameter.number2.name',- detail: 'formula.functionList.LOG10.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.LOG10.functionParameter.number.name',+ detail: 'formula.functionList.LOG10.functionParameter.number.detail',+ example: '100000',require: 1,repeat: 0,},@@ -917,16 +896,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.MROUND.abstract',functionParameter: [{- name: 'formula.functionList.MROUND.functionParameter.number1.name',- detail: 'formula.functionList.MROUND.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.MROUND.functionParameter.number.name',+ detail: 'formula.functionList.MROUND.functionParameter.number.detail',+ example: '10',require: 1,repeat: 0,},{- name: 'formula.functionList.MROUND.functionParameter.number2.name',- detail: 'formula.functionList.MROUND.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.MROUND.functionParameter.multiple.name',+ detail: 'formula.functionList.MROUND.functionParameter.multiple.detail',+ example: '3',require: 1,repeat: 0,},@@ -983,16 +962,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ODD.abstract',functionParameter: [{- name: 'formula.functionList.ODD.functionParameter.number1.name',- detail: 'formula.functionList.ODD.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.ODD.functionParameter.number2.name',- detail: 'formula.functionList.ODD.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ODD.functionParameter.number.name',+ detail: 'formula.functionList.ODD.functionParameter.number.detail',+ example: '1.5',require: 1,repeat: 0,},@@ -1004,20 +976,6 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [description: 'formula.functionList.PI.description',abstract: 'formula.functionList.PI.abstract',functionParameter: [- {- name: 'formula.functionList.PI.functionParameter.number1.name',- detail: 'formula.functionList.PI.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.PI.functionParameter.number2.name',- detail: 'formula.functionList.PI.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },],},{@@ -1093,16 +1051,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.RADIANS.abstract',functionParameter: [{- name: 'formula.functionList.RADIANS.functionParameter.number1.name',- detail: 'formula.functionList.RADIANS.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.RADIANS.functionParameter.number2.name',- detail: 'formula.functionList.RADIANS.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.RADIANS.functionParameter.angle.name',+ detail: 'formula.functionList.RADIANS.functionParameter.angle.detail',+ example: '270',require: 1,repeat: 0,},@@ -1114,20 +1065,6 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [description: 'formula.functionList.RAND.description',abstract: 'formula.functionList.RAND.abstract',functionParameter: [- {- name: 'formula.functionList.RAND.functionParameter.number1.name',- detail: 'formula.functionList.RAND.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.RAND.functionParameter.number2.name',- detail: 'formula.functionList.RAND.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },],},{@@ -1137,17 +1074,38 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.RANDARRAY.abstract',functionParameter: [{- name: 'formula.functionList.RANDARRAY.functionParameter.number1.name',- detail: 'formula.functionList.RANDARRAY.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.RANDARRAY.functionParameter.rows.name',+ detail: 'formula.functionList.RANDARRAY.functionParameter.rows.detail',+ example: '5',+ require: 0,repeat: 0,},{- name: 'formula.functionList.RANDARRAY.functionParameter.number2.name',- detail: 'formula.functionList.RANDARRAY.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,+ name: 'formula.functionList.RANDARRAY.functionParameter.columns.name',+ detail: 'formula.functionList.RANDARRAY.functionParameter.columns.detail',+ example: '3',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.RANDARRAY.functionParameter.min.name',+ detail: 'formula.functionList.RANDARRAY.functionParameter.min.detail',+ example: '1',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.RANDARRAY.functionParameter.max.name',+ detail: 'formula.functionList.RANDARRAY.functionParameter.max.detail',+ example: '100',+ require: 0,+ repeat: 0,+ },+ {+ name: 'formula.functionList.RANDARRAY.functionParameter.wholeNumber.name',+ detail: 'formula.functionList.RANDARRAY.functionParameter.wholeNumber.detail',+ example: 'TRUE',+ require: 0,repeat: 0,},],@@ -1159,16 +1117,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.RANDBETWEEN.abstract',functionParameter: [{- name: 'formula.functionList.RANDBETWEEN.functionParameter.number1.name',- detail: 'formula.functionList.RANDBETWEEN.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.RANDBETWEEN.functionParameter.bottom.name',+ detail: 'formula.functionList.RANDBETWEEN.functionParameter.bottom.detail',+ example: '1',require: 1,repeat: 0,},{- name: 'formula.functionList.RANDBETWEEN.functionParameter.number2.name',- detail: 'formula.functionList.RANDBETWEEN.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.RANDBETWEEN.functionParameter.top.name',+ detail: 'formula.functionList.RANDBETWEEN.functionParameter.top.detail',+ example: '100',require: 1,repeat: 0,},@@ -1203,16 +1161,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ROUND.abstract',functionParameter: [{- name: 'formula.functionList.ROUND.functionParameter.number1.name',- detail: 'formula.functionList.ROUND.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUND.functionParameter.number.name',+ detail: 'formula.functionList.ROUND.functionParameter.number.detail',+ example: '2.15',require: 1,repeat: 0,},{- name: 'formula.functionList.ROUND.functionParameter.number2.name',- detail: 'formula.functionList.ROUND.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUND.functionParameter.numDigits.name',+ detail: 'formula.functionList.ROUND.functionParameter.numDigits.detail',+ example: '1',require: 1,repeat: 0,},@@ -1225,16 +1183,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ROUNDDOWN.abstract',functionParameter: [{- name: 'formula.functionList.ROUNDDOWN.functionParameter.number1.name',- detail: 'formula.functionList.ROUNDDOWN.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUNDDOWN.functionParameter.number.name',+ detail: 'formula.functionList.ROUNDDOWN.functionParameter.number.detail',+ example: '3.2',require: 1,repeat: 0,},{- name: 'formula.functionList.ROUNDDOWN.functionParameter.number2.name',- detail: 'formula.functionList.ROUNDDOWN.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUNDDOWN.functionParameter.numDigits.name',+ detail: 'formula.functionList.ROUNDDOWN.functionParameter.numDigits.detail',+ example: '0',require: 1,repeat: 0,},@@ -1247,16 +1205,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.ROUNDUP.abstract',functionParameter: [{- name: 'formula.functionList.ROUNDUP.functionParameter.number1.name',- detail: 'formula.functionList.ROUNDUP.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUNDUP.functionParameter.number.name',+ detail: 'formula.functionList.ROUNDUP.functionParameter.number.detail',+ example: '3.2',require: 1,repeat: 0,},{- name: 'formula.functionList.ROUNDUP.functionParameter.number2.name',- detail: 'formula.functionList.ROUNDUP.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.ROUNDUP.functionParameter.numDigits.name',+ detail: 'formula.functionList.ROUNDUP.functionParameter.numDigits.detail',+ example: '0',require: 1,repeat: 0,},@@ -1269,16 +1227,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SEC.abstract',functionParameter: [{- name: 'formula.functionList.SEC.functionParameter.number1.name',- detail: 'formula.functionList.SEC.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.SEC.functionParameter.number2.name',- detail: 'formula.functionList.SEC.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SEC.functionParameter.number.name',+ detail: 'formula.functionList.SEC.functionParameter.number.detail',+ example: '30',require: 1,repeat: 0,},@@ -1291,16 +1242,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SECH.abstract',functionParameter: [{- name: 'formula.functionList.SECH.functionParameter.number1.name',- detail: 'formula.functionList.SECH.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.SECH.functionParameter.number2.name',- detail: 'formula.functionList.SECH.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SECH.functionParameter.number.name',+ detail: 'formula.functionList.SECH.functionParameter.number.detail',+ example: '30',require: 1,repeat: 0,},@@ -1409,16 +1353,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SQRT.abstract',functionParameter: [{- name: 'formula.functionList.SQRT.functionParameter.number1.name',- detail: 'formula.functionList.SQRT.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.SQRT.functionParameter.number2.name',- detail: 'formula.functionList.SQRT.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SQRT.functionParameter.number.name',+ detail: 'formula.functionList.SQRT.functionParameter.number.detail',+ example: '16',require: 1,repeat: 0,},@@ -1431,16 +1368,9 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SQRTPI.abstract',functionParameter: [{- name: 'formula.functionList.SQRTPI.functionParameter.number1.name',- detail: 'formula.functionList.SQRTPI.functionParameter.number1.detail',- example: 'A1:A20',- require: 1,- repeat: 0,- },- {- name: 'formula.functionList.SQRTPI.functionParameter.number2.name',- detail: 'formula.functionList.SQRTPI.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SQRTPI.functionParameter.number.name',+ detail: 'formula.functionList.SQRTPI.functionParameter.number.detail',+ example: '1',require: 1,repeat: 0,},@@ -1602,16 +1532,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [{name: 'formula.functionList.SUMSQ.functionParameter.number1.name',detail: 'formula.functionList.SUMSQ.functionParameter.number1.detail',- example: 'A1:A20',+ example: '3',require: 1,repeat: 0,},{name: 'formula.functionList.SUMSQ.functionParameter.number2.name',detail: 'formula.functionList.SUMSQ.functionParameter.number2.detail',- example: 'A1:A20',- require: 1,- repeat: 0,+ example: '4',+ require: 0,+ repeat: 1,},],},@@ -1622,16 +1552,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SUMX2MY2.abstract',functionParameter: [{- name: 'formula.functionList.SUMX2MY2.functionParameter.number1.name',- detail: 'formula.functionList.SUMX2MY2.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMX2MY2.functionParameter.arrayX.name',+ detail: 'formula.functionList.SUMX2MY2.functionParameter.arrayX.detail',+ example: 'A2:A8',require: 1,repeat: 0,},{- name: 'formula.functionList.SUMX2MY2.functionParameter.number2.name',- detail: 'formula.functionList.SUMX2MY2.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMX2MY2.functionParameter.arrayY.name',+ detail: 'formula.functionList.SUMX2MY2.functionParameter.arrayY.detail',+ example: 'B2:B8',require: 1,repeat: 0,},@@ -1644,16 +1574,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SUMX2PY2.abstract',functionParameter: [{- name: 'formula.functionList.SUMX2PY2.functionParameter.number1.name',- detail: 'formula.functionList.SUMX2PY2.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMX2PY2.functionParameter.arrayX.name',+ detail: 'formula.functionList.SUMX2PY2.functionParameter.arrayX.detail',+ example: 'A2:A8',require: 1,repeat: 0,},{- name: 'formula.functionList.SUMX2PY2.functionParameter.number2.name',- detail: 'formula.functionList.SUMX2PY2.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMX2PY2.functionParameter.arrayY.name',+ detail: 'formula.functionList.SUMX2PY2.functionParameter.arrayY.detail',+ example: 'B2:B8',require: 1,repeat: 0,},@@ -1666,16 +1596,16 @@ export const FUNCTION_LIST_MATH: IFunctionInfo[] = [abstract: 'formula.functionList.SUMXMY2.abstract',functionParameter: [{- name: 'formula.functionList.SUMXMY2.functionParameter.number1.name',- detail: 'formula.functionList.SUMXMY2.functionParameter.number1.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMXMY2.functionParameter.arrayX.name',+ detail: 'formula.functionList.SUMXMY2.functionParameter.arrayX.detail',+ example: 'A2:A8',require: 1,repeat: 0,},{- name: 'formula.functionList.SUMXMY2.functionParameter.number2.name',- detail: 'formula.functionList.SUMXMY2.functionParameter.number2.detail',- example: 'A1:A20',+ name: 'formula.functionList.SUMXMY2.functionParameter.arrayY.name',+ detail: 'formula.functionList.SUMXMY2.functionParameter.arrayY.detail',+ example: 'B2:B8',require: 1,repeat: 0,},