Skip to content

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.

fix(formula): get cell value type (#771)

Dushusir78c21e3f898c
diff --git a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
index 5d153bbc23..6542903ab5 100644
--- a/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
+++ b/packages/engine-formula/src/engine/reference-object/base-reference-object.ts
@@ -21,7 +21,7 @@ import { FormulaAstLRU } from '../../basics/cache-lru';
import type { IRuntimeUnitDataType, IUnitData, IUnitSheetNameMap } from '../../basics/common';
import { ERROR_TYPE_SET, ErrorType } from '../../basics/error-type';
import { ObjectClassType } from '../../basics/object-class-type';
-import { ArrayValueObject } from '../value-object/array-value-object';
+import { ArrayValueObject, ValueObjectFactory } from '../value-object/array-value-object';
import { type BaseValueObject, ErrorValueObject, type IArrayValueObject } from '../value-object/base-value-object';
import {
BooleanValueObject,
@@ -334,13 +334,18 @@ export class BaseReferenceObject extends ObjectClassType {
if (ERROR_TYPE_SET.has(value as string)) {
return ErrorValueObject.create(value as ErrorType);
}
- if (cell.t === CellValueType.BOOLEAN) {
- return new BooleanValueObject(value);
+
+ if (cell.t === CellValueType.NUMBER) {
+ return new NumberValueObject(value);
}
- if (cell.t === CellValueType.FORCE_STRING || cell.t === CellValueType.STRING) {
+ if (cell.t === CellValueType.STRING || cell.t === CellValueType.FORCE_STRING) {
return new StringValueObject(value);
}
- return new NumberValueObject(value);
+ if (cell.t === CellValueType.BOOLEAN) {
+ return new BooleanValueObject(value);
+ }
+
+ return ValueObjectFactory.create(value);
}
getCellByRow(row: number) {
diff --git a/packages/engine-formula/src/engine/utils/math-kit.ts b/packages/engine-formula/src/engine/utils/math-kit.ts
index 770fad72b2..1a9ce50b6c 100644
--- a/packages/engine-formula/src/engine/utils/math-kit.ts
+++ b/packages/engine-formula/src/engine/utils/math-kit.ts
@@ -14,15 +14,38 @@
* limitations under the License.
*/
-export function round(number: number, precision: number): number {
+import Big from 'big.js';
+
+/**
+ * Packaging basic mathematical calculation methods, adding precision parameters and solving native JavaScript precision problems
+ */
+
+/**
+ * Native JavaScript: 0.6789 * 10000 = 6788.999999999999
+ *
+ * @param a
+ * @param b
+ * @returns
+ */
+export function multiply(a: number, b: number): number {
+ return Big(a).times(b).toNumber();
+}
+
+export function round(base: number, precision: number): number {
+ const factor = 10 ** Math.floor(precision);
+ return Math.round(multiply(base, factor)) / factor;
+}
+
+export function floor(base: number, precision: number): number {
const factor = 10 ** Math.floor(precision);
- return Math.round(number * factor) / factor;
+ return Math.floor(multiply(base, factor)) / factor;
}
-export function pow(number: number, precision: number) {
- return number ** precision;
+export function ceil(base: number, precision: number): number {
+ const factor = 10 ** Math.floor(precision);
+ return Math.ceil(multiply(base, factor)) / factor;
}
-export function log10(number: number) {
- return Math.log10(number);
+export function pow(base: number, exponent: number): number {
+ return base ** exponent;
}
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-abs.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-abs.spec.ts
new file mode 100644
index 0000000000..57f76d09ab
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-abs.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject abs method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('abs', () => {
+ it('origin nm', () => {
+ expect((originArrayValueObject.abs() as ArrayValueObject).toValue()).toStrictEqual([
+ [1, '#VALUE!', 1.23, 1, 0],
+ [0, 100, 2.34, '#VALUE!', 3],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-acos.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-acos.spec.ts
new file mode 100644
index 0000000000..9d4f44f814
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-acos.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject acos method test', () => {
+ describe('acos', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.acos() as ArrayValueObject).toValue()).toStrictEqual([
+ [0, '#VALUE!', '#NUM!', 0, 1.5707963267948966],
+ [1.5707963267948966, '#NUM!', '#NUM!', '#VALUE!', '#NUM!'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-acosh.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-acosh.spec.ts
new file mode 100644
index 0000000000..a2e752251e
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-acosh.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject acosh method test', () => {
+ describe('acosh', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.acosh() as ArrayValueObject).toValue()).toStrictEqual([
+ [0, '#VALUE!', 0.6658635291565548, 0, '#NUM!'],
+ ['#NUM!', 5.298292365610484, 1.494153066724473, '#VALUE!', '#NUM!'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-asin.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-asin.spec.ts
new file mode 100644
index 0000000000..9eeafebdff
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-asin.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject asin method test', () => {
+ describe('asin', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.asin() as ArrayValueObject).toValue()).toStrictEqual([
+ [1.5707963267948966, '#VALUE!', '#NUM!', 1.5707963267948966, 0],
+ [0, '#NUM!', '#NUM!', '#VALUE!', '#NUM!'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-asinh.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-asinh.spec.ts
new file mode 100644
index 0000000000..dc69793984
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-asinh.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject asinh method test', () => {
+ describe('asinh', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.asinh() as ArrayValueObject).toValue()).toStrictEqual([
+ [0.881373587019543, '#VALUE!', 1.0350378961923077, 0.881373587019543, 0],
+ [0, 5.298342365610589, 1.5861119704218916, '#VALUE!', -1.8184464592320668],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan.spec.ts
new file mode 100644
index 0000000000..670b256407
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject atan method test', () => {
+ describe('atan', () => {
+ it('origin nm, param nm', () => {
+ const atanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((atanArrayValueObject.atan() as ArrayValueObject).toValue()).toStrictEqual([
+ [0.7853981633974483, '#VALUE!', 0.8881737743776796, 0.7853981633974483, 0],
+ [0, 1.5607966601082315, 1.16693653188752, '#VALUE!', -1.2490457723982544],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan2.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan2.spec.ts
new file mode 100644
index 0000000000..57e9c8bb7f
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atan2.spec.ts
@@ -0,0 +1,183 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+import { NumberValueObject } from '../primitive-object';
+
+describe('arrayValueObject atan2 method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, 2, 3, 4, 5],
+ [6, 7, 8, 9, 10],
+ [11, 12, 13, 14, 15],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('atan2', () => {
+ it('origin nm, param nm', () => {
+ const atan2ArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 3, 4],
+ [1, 4, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.atan2(atan2ArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.4636476090008061, 0.5880026035475675, 0.6435011087932844, '#N/A', '#N/A'],
+ [1.4056476493802699, 1.0516502125483738, 1.3258176636680326, '#N/A', '#N/A'],
+ ['#N/A', '#N/A', '#N/A', '#N/A', '#N/A'],
+ ]);
+ });
+
+ it('origin nm, param 1m', () => {
+ const atan2ArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[2, 2, 2, 3, 3]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.atan2(atan2ArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.4636476090008061, 0.7853981633974483, 0.982793723247329, 0.9272952180016122, 1.0303768265243125],
+ [1.2490457723982544, 1.2924966677897853, 1.3258176636680326, 1.2490457723982544, 1.2793395323170296],
+ [1.3909428270024184, 1.4056476493802699, 1.4181469983996315, 1.35970299357215, 1.373400766945016],
+ ]);
+ });
+
+ it('origin nm, param n1', () => {
+ const atan2ArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[3], [2], [1]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.atan2(atan2ArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.3217505543966422, 0.5880026035475675, 0.7853981633974483, 0.9272952180016122, 1.0303768265243125],
+ [1.2490457723982544, 1.2924966677897853, 1.3258176636680326, 1.3521273809209546, 1.373400766945016],
+ [1.4801364395941514, 1.4876550949064553, 1.4940244355251187, 1.4994888620096063, 1.5042281630190728],
+ ]);
+ });
+
+ it('origin 1m, param nm', () => {
+ const atan2ArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[2, 2, 2, 3, 3]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((atan2ArrayValueObject.atan2(originArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1.1071487177940904, 0.7853981633974483, 0.5880026035475675, 0.6435011087932844, 0.5404195002705842],
+ [0.3217505543966422, 0.27829965900511133, 0.24497866312686414, 0.3217505543966422, 0.2914567944778671],
+ [
+ 0.17985349979247828, 0.16514867741462683, 0.15264932839526518, 0.21109333322274654,
+ 0.19739555984988078,
+ ],
+ ]);
+ });
+
+ it('origin n1, param nm', () => {
+ const atan2ArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[3], [2], [1]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((atan2ArrayValueObject.atan2(originArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1.2490457723982544, 0.982793723247329, 0.7853981633974483, 0.6435011087932844, 0.5404195002705842],
+ [
+ 0.3217505543966422, 0.27829965900511133, 0.24497866312686414, 0.21866894587394195,
+ 0.19739555984988078,
+ ],
+ [
+ 0.09065988720074511, 0.08314123188844122, 0.07677189126977804, 0.07130746478529032,
+ 0.06656816377582381,
+ ],
+ ]);
+ });
+
+ it('origin nm multiple formats, param 1 number', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const roundValueObject = new NumberValueObject(1);
+
+ expect((originArrayValueObject.atan2(roundValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.7853981633974483, '#VALUE!', 0.8881737743776796, 0.7853981633974483, 0],
+ [0, 1.5607966601082315, 1.16693653188752, '#VALUE!', -1.2490457723982544],
+ ]);
+ });
+
+ it('origin 1 number, param nm multiple formats', () => {
+ const originValueObject = new NumberValueObject(1);
+ const roundArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originValueObject.atan2(roundArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.7853981633974483, '#VALUE!', 0.682622552417217, 0.7853981633974483, 1.5707963267948966],
+ [1.5707963267948966, 0.009999666686665238, 0.40385979490737667, '#VALUE!', 2.819842099193151],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-atanh.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atanh.spec.ts
new file mode 100644
index 0000000000..aac11d8386
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-atanh.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject atanh method test', () => {
+ describe('atanh', () => {
+ it('origin nm, param nm', () => {
+ const atanhArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((atanhArrayValueObject.atanh() as ArrayValueObject).toValue()).toStrictEqual([
+ ['#NUM!', '#VALUE!', '#NUM!', '#NUM!', 0],
+ [0, '#NUM!', '#NUM!', '#VALUE!', '#NUM!'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-cbrt.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-cbrt.spec.ts
new file mode 100644
index 0000000000..c56b521613
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-cbrt.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject cbrt method test', () => {
+ describe('cbrt', () => {
+ it('origin nm, param nm', () => {
+ const cbrtArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((cbrtArrayValueObject.cbrt() as ArrayValueObject).toValue()).toStrictEqual([
+ [2, 1, '#VALUE!', 1.0714412696907731, 1, 0],
+ [3, 0, 4.641588833612779, 1.3276143942617729, '#VALUE!', -1.4422495703074083],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-ceil.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-ceil.spec.ts
new file mode 100644
index 0000000000..7ec9c60c09
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-ceil.spec.ts
@@ -0,0 +1,201 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+import { NumberValueObject } from '../primitive-object';
+
+describe('arrayValueObject ceil method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [0.1234, 0.9876, 0.5432, 0.6789, 0.4567],
+ [0.2345, 0.8765, 0.321, 0.7654, 0.5432],
+ [0.3456, 0.7654, 0.2109, 0.6543, 0.6789],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('ceil', () => {
+ it('origin nm, param nm', () => {
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 3, 4],
+ [1, 4, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.13, 0.988, 0.5432, '#N/A', '#N/A'],
+ [0.3, 0.8765, 0.33, '#N/A', '#N/A'],
+ ['#N/A', '#N/A', '#N/A', '#N/A', '#N/A'],
+ ]);
+ });
+
+ it('origin nm, param 1m', () => {
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[2, 2, 2, 3, 3]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.13, 0.99, 0.55, 0.679, 0.457],
+ [0.24, 0.88, 0.33, 0.766, 0.544],
+ [0.35, 0.77, 0.22, 0.655, 0.679],
+ ]);
+ });
+
+ it('origin nm, param n1', () => {
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[3], [2], [1]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.124, 0.988, 0.544, 0.679, 0.457],
+ [0.24, 0.88, 0.33, 0.77, 0.55],
+ [0.4, 0.8, 0.3, 0.7, 0.7],
+ ]);
+ });
+
+ it('origin 1m, param nm', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[0.1234, 0.9876, 0.5432, 0.6789, 0.4567]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 2, 2, 3, 3],
+ [3, 3, 3, 4, 4],
+ [4, 4, 4, 5, 5],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.13, 0.99, 0.55, 0.679, 0.457],
+ [0.124, 0.988, 0.544, 0.6789, 0.4567],
+ [0.1234, 0.9876, 0.5432, 0.6789, 0.4567],
+ ]);
+ });
+
+ it('origin n1, param nm', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[0.1234], [0.2345], [0.3456]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 2, 2, 3, 3],
+ [3, 3, 3, 4, 4],
+ [4, 4, 4, 5, 5],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.13, 0.13, 0.13, 0.124, 0.124],
+ [0.235, 0.235, 0.235, 0.2345, 0.2345],
+ [0.3456, 0.3456, 0.3456, 0.3456, 0.3456],
+ ]);
+ });
+
+ it('origin nm multiple formats, param 1 number', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ const ceilValueObject = new NumberValueObject(1);
+
+ expect((originArrayValueObject.ceil(ceilValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1, '#VALUE!', 1.3, 1, 0],
+ [0, 100, 2.4, '#VALUE!', -3],
+ ]);
+ });
+
+ it('origin 1 number, param nm multiple formats', () => {
+ const originValueObject = new NumberValueObject(1);
+ const ceilArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originValueObject.ceil(ceilArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1, '#VALUE!', 1, 1, 1],
+ [1, 1, 1, '#VALUE!', 1000],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-cos.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-cos.spec.ts
new file mode 100644
index 0000000000..30657edc72
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-cos.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject cos method test', () => {
+ describe('cos', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.cos() as ArrayValueObject).toValue()).toStrictEqual([
+ [-0.14550003380861354, 0.5403023058681398, '#VALUE!', 0.3342377271245026, 0.5403023058681398, 1],
+ [-0.2921388087338362, 1, 0.8623188722876839, -0.695563326462902, '#VALUE!', -0.9899924966004454],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-exp.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-exp.spec.ts
new file mode 100644
index 0000000000..28e378dfcf
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-exp.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject exp method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('exp', () => {
+ it('origin nm', () => {
+ expect((originArrayValueObject.exp() as ArrayValueObject).toValue()).toStrictEqual([
+ [2.718281828459045, '#VALUE!', 3.4212295362896734, 2.718281828459045, 1],
+ [1, 2.6881171418161356e43, 10.381236562731843, '#VALUE!', 0.049787068367863944],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-floor.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-floor.spec.ts
new file mode 100644
index 0000000000..0618077dbb
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-floor.spec.ts
@@ -0,0 +1,201 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+import { NumberValueObject } from '../primitive-object';
+
+describe('arrayValueObject floor method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [0.1234, 0.9876, 0.5432, 0.6789, 0.4567],
+ [0.2345, 0.8765, 0.321, 0.7654, 0.5432],
+ [0.3456, 0.7654, 0.2109, 0.6543, 0.6789],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('floor', () => {
+ it('origin nm, param nm', () => {
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 3, 4],
+ [1, 4, 2],
+ ]),
+ rowCount: 2,
+ columnCount: 3,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.12, 0.987, 0.5432, '#N/A', '#N/A'],
+ [0.2, 0.8765, 0.32, '#N/A', '#N/A'],
+ ['#N/A', '#N/A', '#N/A', '#N/A', '#N/A'],
+ ]);
+ });
+
+ it('origin nm, param 1m', () => {
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[2, 2, 2, 3, 3]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.12, 0.98, 0.54, 0.678, 0.456],
+ [0.23, 0.87, 0.32, 0.765, 0.543],
+ [0.34, 0.76, 0.21, 0.654, 0.678],
+ ]);
+ });
+
+ it('origin nm, param n1', () => {
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[3], [2], [1]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.123, 0.987, 0.543, 0.678, 0.456],
+ [0.23, 0.87, 0.32, 0.76, 0.54],
+ [0.3, 0.7, 0.2, 0.6, 0.6],
+ ]);
+ });
+
+ it('origin 1m, param nm', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[0.1234, 0.9876, 0.5432, 0.6789, 0.4567]]),
+ rowCount: 1,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 2, 2, 3, 3],
+ [3, 3, 3, 4, 4],
+ [4, 4, 4, 5, 5],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.12, 0.98, 0.54, 0.678, 0.456],
+ [0.123, 0.987, 0.543, 0.6789, 0.4567],
+ [0.1234, 0.9876, 0.5432, 0.6789, 0.4567],
+ ]);
+ });
+
+ it('origin n1, param nm', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([[0.1234], [0.2345], [0.3456]]),
+ rowCount: 3,
+ columnCount: 1,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [2, 2, 2, 3, 3],
+ [3, 3, 3, 4, 4],
+ [4, 4, 4, 5, 5],
+ ]),
+ rowCount: 3,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originArrayValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [0.12, 0.12, 0.12, 0.123, 0.123],
+ [0.234, 0.234, 0.234, 0.2345, 0.2345],
+ [0.3456, 0.3456, 0.3456, 0.3456, 0.3456],
+ ]);
+ });
+
+ it('origin nm multiple formats, param 1 number', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ const floorValueObject = new NumberValueObject(1);
+
+ expect((originArrayValueObject.floor(floorValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1, '#VALUE!', 1.2, 1, 0],
+ [0, 100, 2.3, '#VALUE!', -3],
+ ]);
+ });
+
+ it('origin 1 number, param nm multiple formats', () => {
+ const originValueObject = new NumberValueObject(1);
+ const floorArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [1, ' ', 1.23, true, false],
+ [0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 5,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((originValueObject.floor(floorArrayValueObject) as ArrayValueObject).toValue()).toStrictEqual([
+ [1, '#VALUE!', 1, 1, 1],
+ [1, 1, 1, '#VALUE!', 0],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-log.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-log.spec.ts
new file mode 100644
index 0000000000..b67efa409b
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-log.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject log method test', () => {
+ const originArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ describe('log', () => {
+ it('origin nm', () => {
+ expect((originArrayValueObject.log() as ArrayValueObject).toValue()).toStrictEqual([
+ [2.0794415416798357, 0, '#VALUE!', 0.2070141693843261, 0, '#NUM!'],
+ [3.295836866004329, '#NUM!', 4.605170185988092, 0.85015092936961, '#VALUE!', '#NUM!'],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-log10.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-log10.spec.ts
index 96068b8479..6ce4837c79 100644
--- a/packages/engine-formula/src/engine/value-object/__tests__/array-value-log10.spec.ts
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-log10.spec.ts
@@ -22,11 +22,11 @@ import { ArrayValueObject, transformToValueObject } from '../array-value-object'
describe('arrayValueObject log10 method test', () => {
const originArrayValueObject = new ArrayValueObject({
calculateValueList: transformToValueObject([
- [1, ' ', 1.23, true, false],
- [0, '100', '2.34', 'test', -3],
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
]),
rowCount: 2,
- columnCount: 5,
+ columnCount: 6,
unitId: '',
sheetId: '',
row: 0,
@@ -36,8 +36,8 @@ describe('arrayValueObject log10 method test', () => {
describe('log10', () => {
it('origin nm', () => {
expect((originArrayValueObject.log10() as ArrayValueObject).toValue()).toStrictEqual([
- [0, '#VALUE!', 0.08990511143939792, 0, '#NUM!'],
- ['#NUM!', 2, 0.36921585741014284, '#VALUE!', '#NUM!'],
+ [0.9030899869919435, 0, '#VALUE!', 0.08990511143939792, 0, '#NUM!'],
+ [1.4313637641589874, '#NUM!', 2, 0.36921585741014284, '#VALUE!', '#NUM!'],
]);
});
});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
index acdc48cc14..b8c6ee10ff 100644
--- a/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-object.spec.ts
@@ -17,7 +17,8 @@
/* eslint-disable no-magic-numbers */
import { describe, expect, it } from 'vitest';
-import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+import { ArrayValueObject, transformToValueObject, ValueObjectFactory } from '../array-value-object';
+import type { BooleanValueObject, NumberValueObject } from '../primitive-object';
describe('arrayValueObject test', () => {
const originArrayValueObject = new ArrayValueObject({
@@ -124,4 +125,85 @@ describe('arrayValueObject test', () => {
expect(originArrayValueObject.pick(pickArrayValueObject).sum().getValue()).toStrictEqual(43);
});
});
+
+ describe('ValueObjectFactory', () => {
+ it('ValueObjectFactory create BooleanValueObject ', () => {
+ let booleanValueObject = ValueObjectFactory.create(true);
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+
+ booleanValueObject = ValueObjectFactory.create(false);
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+
+ booleanValueObject = ValueObjectFactory.create('true');
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+
+ booleanValueObject = ValueObjectFactory.create('false');
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+ booleanValueObject = ValueObjectFactory.create('TRUE');
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+
+ booleanValueObject = ValueObjectFactory.create('FALSE');
+
+ expect((booleanValueObject as BooleanValueObject).isBoolean()).toBeTruthy();
+ });
+ it('ValueObjectFactory create NumberValueObject ', () => {
+ let numberValueObject = ValueObjectFactory.create(1);
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+
+ numberValueObject = ValueObjectFactory.create(0);
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+ numberValueObject = ValueObjectFactory.create(-1);
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+
+ numberValueObject = ValueObjectFactory.create('1');
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+
+ numberValueObject = ValueObjectFactory.create(1e2);
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+
+ numberValueObject = ValueObjectFactory.create('1e2');
+
+ expect((numberValueObject as NumberValueObject).isNumber()).toBeTruthy();
+ });
+
+ it('ValueObjectFactory create ArrayValueObject ', () => {
+ let arrayValueObject = ValueObjectFactory.create('{1,2,3;4,5,6}');
+
+ expect((arrayValueObject as ArrayValueObject).isArray()).toBeTruthy();
+
+ arrayValueObject = ValueObjectFactory.create('{1,2,3;4,5,6}');
+
+ expect((arrayValueObject as ArrayValueObject).isArray()).toBeTruthy();
+ });
+
+ it('ValueObjectFactory create StringValueObject ', () => {
+ const stringValueObject = ValueObjectFactory.create('test');
+
+ expect(stringValueObject.isString()).toBeTruthy();
+ });
+
+ it('ValueObjectFactory create ErrorValueObject ', () => {
+ let errorValueObject = ValueObjectFactory.create(NaN);
+
+ expect(errorValueObject.isError()).toBeTruthy();
+
+ errorValueObject = ValueObjectFactory.create(Infinity);
+
+ expect(errorValueObject.isError()).toBeTruthy();
+
+ errorValueObject = ValueObjectFactory.create(-Infinity);
+
+ expect(errorValueObject.isError()).toBeTruthy();
+ });
+ });
});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-sin.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-sin.spec.ts
new file mode 100644
index 0000000000..ce5f054425
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-sin.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject sin method test', () => {
+ describe('sin', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.sin() as ArrayValueObject).toValue()).toStrictEqual([
+ [0.9893582466233818, 0.8414709848078965, '#VALUE!', 0.9424888019316975, 0.8414709848078965, 0],
+ [0.956375928404503, 0, -0.5063656411097588, 0.7184647930691261, '#VALUE!', -0.1411200080598672],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-tan.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-tan.spec.ts
new file mode 100644
index 0000000000..910cf5e612
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-tan.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject tan method test', () => {
+ describe('tan', () => {
+ it('origin nm, param nm', () => {
+ const tanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((tanArrayValueObject.tan() as ArrayValueObject).toValue()).toStrictEqual([
+ [-6.799711455220379, 1.5574077246549023, '#VALUE!', 2.819815734268152, 1.5574077246549023, 0],
+ [-3.273703800428119, 0, -0.5872139151569291, -1.032925063376592, '#VALUE!', 0.1425465430742778],
+ ]);
+ });
+ });
+});
diff --git a/packages/engine-formula/src/engine/value-object/__tests__/array-value-tanh.spec.ts b/packages/engine-formula/src/engine/value-object/__tests__/array-value-tanh.spec.ts
new file mode 100644
index 0000000000..f354ded0c0
--- /dev/null
+++ b/packages/engine-formula/src/engine/value-object/__tests__/array-value-tanh.spec.ts
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+
+/* eslint-disable no-magic-numbers */
+import { describe, expect, it } from 'vitest';
+
+import { ArrayValueObject, transformToValueObject } from '../array-value-object';
+
+describe('arrayValueObject tanh method test', () => {
+ describe('tanh', () => {
+ it('origin nm, param nm', () => {
+ const atanArrayValueObject = new ArrayValueObject({
+ calculateValueList: transformToValueObject([
+ [8, 1, ' ', 1.23, true, false],
+ [27, 0, '100', '2.34', 'test', -3],
+ ]),
+ rowCount: 2,
+ columnCount: 6,
+ unitId: '',
+ sheetId: '',
+ row: 0,
+ column: 0,
+ });
+
+ expect((atanArrayValueObject.tanh() as ArrayValueObject).toValue()).toStrictEqual([
+ [0.9999997749296758, 0.7615941559557649, '#VALUE!', 0.8425793256589296, 0.7615941559557649, 0],
+ [1, 0, 1, 0.9816125892654238, '#VALUE!', -0.9950547536867305],
+ ]);
+ });
+ });
+});
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.ts
index a726825b01..a86c29cd3b 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
@@ -38,6 +38,9 @@ enum BatchOperatorType {
LIKE,
POW,
ROUND,
+ FLOOR,
+ CEIL,
+ ATAN2,
}
enum ArrayCalculateType {
@@ -588,6 +591,42 @@ export class ArrayValueObject extends BaseValueObject {
});
}
+ override cbrt(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).cbrt();
+ });
+ }
+
+ override cos(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).cos();
+ });
+ }
+
+ override acos(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).acos();
+ });
+ }
+
+ override acosh(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).acosh();
+ });
+ }
+
override sin(): BaseValueObject {
return this.map((currentValue) => {
if (currentValue.isError()) {
@@ -597,6 +636,73 @@ export class ArrayValueObject extends BaseValueObject {
});
}
+ override asin(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).asin();
+ });
+ }
+
+ override asinh(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).asinh();
+ });
+ }
+
+ override tan(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).tan();
+ });
+ }
+
+ override tanh(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).tanh();
+ });
+ }
+
+ override atan(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).atan();
+ });
+ }
+
+ override atanh(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).atanh();
+ });
+ }
+
+ override atan2(valueObject: BaseValueObject): BaseValueObject {
+ return this._batchOperator(valueObject, BatchOperatorType.ATAN2);
+ }
+
+ override atan2Inverse(valueObject: BaseValueObject): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (valueObject as BaseValueObject).atan2(currentValue as BaseValueObject);
+ });
+ }
+
override mean(): BaseValueObject {
const sum = this.sum();
@@ -626,6 +732,61 @@ export class ArrayValueObject extends BaseValueObject {
return allValue.get(0, (count - 1) / 2);
}
+ override var(): BaseValueObject {
+ const allValue = this.flatten();
+
+ const mean = this.mean();
+
+ let isError = null;
+ const squaredDifferences: BaseValueObject[][] = [];
+ allValue.iterator((valueObject: Nullable<BaseValueObject>, row: number, column: number) => {
+ let baseValueObject = null;
+
+ if (valueObject && valueObject.isError()) {
+ isError = true;
+ return false; // break
+ }
+
+ if (valueObject == null) {
+ baseValueObject = new NumberValueObject(0);
+ } else {
+ baseValueObject = (valueObject as BaseValueObject).minus(mean).pow(new NumberValueObject(2, true));
+ }
+
+ if (squaredDifferences[row] == null) {
+ squaredDifferences[row] = [];
+ }
+
+ squaredDifferences[row][column] = baseValueObject;
+ });
+
+ if (isError) {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ return new ArrayValueObject('').mean();
+
+ // TODO@Dushusir: use squaredDifferences
+ // const sum = new ArrayValueObject({
+ // calculateValueList: squaredDifferences,
+ // rowCount: number;
+ // columnCount: number;
+ // unitId: string;
+ // sheetId: string;
+ // row: number;
+ // column: number;
+ // }).sum();
+ }
+
+ override log(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).log();
+ });
+ }
+
override log10(): BaseValueObject {
return this.map((currentValue) => {
if (currentValue.isError()) {
@@ -635,6 +796,24 @@ export class ArrayValueObject extends BaseValueObject {
});
}
+ override exp(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).exp();
+ });
+ }
+
+ override abs(): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (currentValue as BaseValueObject).abs();
+ });
+ }
+
override round(valueObject: BaseValueObject): BaseValueObject {
return this._batchOperator(valueObject, BatchOperatorType.ROUND);
}
@@ -648,6 +827,32 @@ export class ArrayValueObject extends BaseValueObject {
});
}
+ override floor(valueObject: BaseValueObject): BaseValueObject {
+ return this._batchOperator(valueObject, BatchOperatorType.FLOOR);
+ }
+
+ override floorInverse(valueObject: BaseValueObject): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (valueObject as BaseValueObject).floor(currentValue as BaseValueObject);
+ });
+ }
+
+ override ceil(valueObject: BaseValueObject): BaseValueObject {
+ return this._batchOperator(valueObject, BatchOperatorType.CEIL);
+ }
+
+ override ceilInverse(valueObject: BaseValueObject): BaseValueObject {
+ return this.map((currentValue) => {
+ if (currentValue.isError()) {
+ return currentValue;
+ }
+ return (valueObject as BaseValueObject).ceil(currentValue as BaseValueObject);
+ });
+ }
+
toValue() {
return transformToValue(this._value);
}
@@ -912,6 +1117,15 @@ export class ArrayValueObject extends BaseValueObject {
case BatchOperatorType.ROUND:
result[r][column] = (currentValue as BaseValueObject).round(valueObject);
break;
+ case BatchOperatorType.FLOOR:
+ result[r][column] = (currentValue as BaseValueObject).floor(valueObject);
+ break;
+ case BatchOperatorType.ATAN2:
+ result[r][column] = (currentValue as BaseValueObject).atan2(valueObject);
+ break;
+ case BatchOperatorType.CEIL:
+ result[r][column] = (currentValue as BaseValueObject).ceil(valueObject);
+ break;
}
}
} else {
@@ -1058,6 +1272,15 @@ export class ArrayValueObject extends BaseValueObject {
case BatchOperatorType.ROUND:
rowList[c] = (currentValue as BaseValueObject).round(opValue as BaseValueObject);
break;
+ case BatchOperatorType.ATAN2:
+ rowList[c] = (currentValue as BaseValueObject).atan2(opValue as BaseValueObject);
+ break;
+ case BatchOperatorType.FLOOR:
+ rowList[c] = (currentValue as BaseValueObject).floor(opValue as BaseValueObject);
+ break;
+ case BatchOperatorType.CEIL:
+ rowList[c] = (currentValue as BaseValueObject).ceil(opValue as BaseValueObject);
+ break;
}
}
}
@@ -1172,6 +1395,9 @@ export class ValueObjectFactory {
return new StringValueObject(rawValue);
}
if (typeof rawValue === 'number') {
+ if (!Number.isFinite(rawValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
return new NumberValueObject(rawValue, true);
}
return ErrorValueObject.create(ErrorType.NA);
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.ts
index 564b736b52..7db6dd8db7 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
@@ -230,26 +230,133 @@ export class BaseValueObject extends ObjectClassType {
return ErrorValueObject.create(ErrorType.VALUE);
}
+ cbrt(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ cos(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ acos(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ acosh(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
sin(): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.VALUE);
}
+ asin(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ asinh(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ tan(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ tanh(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ atan(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ atan2(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ atan2Inverse(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ atanh(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ /**
+ * Calculate the mean of the entire array.
+ *
+ * reference https://numpy.org/doc/stable/reference/generated/numpy.mean.html#numpy.mean
+ *
+ */
mean(): BaseValueObject {
/** abstract */
return this;
}
+ /**
+ * Calculate the median of the entire array.
+ *
+ * https://numpy.org/doc/stable/reference/generated/numpy.median.html
+ *
+ */
median(): BaseValueObject {
/** abstract */
return this;
}
+ /**
+ * Calculate the variance of the entire array.
+ *
+ * https://numpy.org/doc/stable/reference/generated/numpy.var.html
+ */
+ var(): BaseValueObject {
+ /** abstract */
+ return this;
+ }
+
+ /**
+ * Calculate the standard deviation of the entire array.
+ *
+ * https://numpy.org/doc/stable/reference/generated/numpy.std.html
+ */
+ std(): BaseValueObject {
+ /** abstract */
+ return this;
+ }
+
+ log(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
log10(): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.VALUE);
}
+ exp(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ abs(): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
round(valueObject: BaseValueObject): BaseValueObject {
/** abstract */
return ErrorValueObject.create(ErrorType.VALUE);
@@ -259,6 +366,26 @@ export class BaseValueObject extends ObjectClassType {
/** abstract */
return ErrorValueObject.create(ErrorType.VALUE);
}
+
+ floor(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ floorInverse(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ ceil(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+
+ ceilInverse(valueObject: BaseValueObject): BaseValueObject {
+ /** abstract */
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
}
export class ErrorValueObject extends BaseValueObject {
diff --git a/packages/engine-formula/src/engine/value-object/primitive-object.ts b/packages/engine-formula/src/engine/value-object/primitive-object.ts
index 1af003a8bd..7498c945ec 100644
--- a/packages/engine-formula/src/engine/value-object/primitive-object.ts
+++ b/packages/engine-formula/src/engine/value-object/primitive-object.ts
@@ -21,7 +21,7 @@ import { BooleanValue, ConcatenateType } from '../../basics/common';
import { ErrorType } from '../../basics/error-type';
import { compareToken } from '../../basics/token';
import { compareWithWildcard } from '../utils/compare';
-import { log10, pow, round } from '../utils/math-kit';
+import { ceil, floor, pow, round } from '../utils/math-kit';
import { BaseValueObject, ErrorValueObject } from './base-value-object';
export class NullValueObject extends BaseValueObject {
@@ -103,17 +103,81 @@ export class NullValueObject extends BaseValueObject {
return new NumberValueObject(0, true);
}
+ override cbrt(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override cos(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override acos(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override acosh(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
override sin(): BaseValueObject {
return new NumberValueObject(0, true);
}
+ override asin(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override asinh(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override tan(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override tanh(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override atan(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override atan2(valueObject: BaseValueObject): BaseValueObject {
+ return new NumberValueObject(0, true).atan2(valueObject);
+ }
+
+ override atanh(): BaseValueObject {
+ return new NumberValueObject(0, true);
+ }
+
+ override log(): BaseValueObject {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
override log10(): BaseValueObject {
return ErrorValueObject.create(ErrorType.NUM);
}
+ override exp(): BaseValueObject {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ override abs(): BaseValueObject {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
override round(valueObject: BaseValueObject): BaseValueObject {
return new NumberValueObject(0, true).round(valueObject);
}
+
+ override floor(valueObject: BaseValueObject): BaseValueObject {
+ return new NumberValueObject(0, true).floor(valueObject);
+ }
+
+ override ceil(valueObject: BaseValueObject): BaseValueObject {
+ return new NumberValueObject(0, true).ceil(valueObject);
+ }
}
export class BooleanValueObject extends BaseValueObject {
@@ -214,17 +278,81 @@ export class BooleanValueObject extends BaseValueObject {
return this._convertTonNumber();
}
+ override cbrt(): BaseValueObject {
+ return this._convertTonNumber();
+ }
+
+ override cos(): BaseValueObject {
+ return this._convertTonNumber().cos();
+ }
+
+ override acos(): BaseValueObject {
+ return this._convertTonNumber().acos();
+ }
+
+ override acosh(): BaseValueObject {
+ return this._convertTonNumber().acosh();
+ }
+
override sin(): BaseValueObject {
return this._convertTonNumber().sin();
}
+ override asin(): BaseValueObject {
+ return this._convertTonNumber().asin();
+ }
+
+ override asinh(): BaseValueObject {
+ return this._convertTonNumber().asinh();
+ }
+
+ override tan(): BaseValueObject {
+ return this._convertTonNumber().tan();
+ }
+
+ override tanh(): BaseValueObject {
+ return this._convertTonNumber().tanh();
+ }
+
+ override atan(): BaseValueObject {
+ return this._convertTonNumber().atan();
+ }
+
+ override atan2(valueObject: BaseValueObject): BaseValueObject {
+ return this._convertTonNumber().atan2(valueObject);
+ }
+
+ override atanh(): BaseValueObject {
+ return this._convertTonNumber().atanh();
+ }
+
+ override log(): BaseValueObject {
+ return this._convertTonNumber().log();
+ }
+
override log10(): BaseValueObject {
return this._convertTonNumber().log10();
}
+ override exp(): BaseValueObject {
+ return this._convertTonNumber().exp();
+ }
+
+ override abs(): BaseValueObject {
+ return this._convertTonNumber().abs();
+ }
+
override round(valueObject: BaseValueObject): BaseValueObject {
return this._convertTonNumber().round(valueObject);
}
+
+ override floor(valueObject: BaseValueObject): BaseValueObject {
+ return this._convertTonNumber().floor(valueObject);
+ }
+
+ override ceil(valueObject: BaseValueObject): BaseValueObject {
+ return this._convertTonNumber().ceil(valueObject);
+ }
}
export class NumberValueObject extends BaseValueObject {
@@ -336,10 +464,17 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.VALUE);
}
if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(currentValue + value);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Big(currentValue).plus(value).toNumber());
+
+ const result = Big(currentValue).plus(value).toNumber();
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
return new NumberValueObject(
@@ -357,10 +492,17 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.VALUE);
}
if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(currentValue - value);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Big(currentValue).minus(value).toNumber();
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Big(currentValue).minus(value).toNumber());
+
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
return new NumberValueObject(
@@ -378,10 +520,16 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.VALUE);
}
if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(currentValue * value);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Big(currentValue).times(value).toNumber();
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Big(currentValue).times(value).toNumber());
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
return new NumberValueObject(
@@ -402,10 +550,17 @@ export class NumberValueObject extends BaseValueObject {
if (value === 0) {
return ErrorValueObject.create(ErrorType.DIV_BY_ZERO);
}
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(currentValue / value);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Big(currentValue).div(value).toNumber());
+
+ const result = Big(currentValue).div(value).toNumber();
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
if (value === false) {
@@ -433,7 +588,7 @@ export class NumberValueObject extends BaseValueObject {
break;
}
} else if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
result = this._compareInfinity(currentValue, value, operator);
} else {
switch (operator) {
@@ -486,10 +641,17 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.VALUE);
}
if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(Infinity);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(pow(currentValue, value));
+
+ const result = pow(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
return new NumberValueObject(pow(currentValue, value ? 1 : 0));
@@ -501,19 +663,244 @@ export class NumberValueObject extends BaseValueObject {
override sqrt(): BaseValueObject {
const currentValue = this.getValue();
- if (Math.abs(currentValue) === Infinity) {
- return new NumberValueObject(Infinity);
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Big(currentValue).sqrt().toNumber();
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override cbrt(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Big(currentValue).sqrt().toNumber());
+
+ const result = Math.cbrt(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override cos(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.cos(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override acos(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.acos(currentValue);
+
+ if (Number.isNaN(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override acosh(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.acosh(currentValue);
+
+ if (Number.isNaN(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
}
override sin(): BaseValueObject {
const currentValue = this.getValue();
- if (Math.abs(currentValue) === Infinity) {
- return new NumberValueObject(Infinity);
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.sin(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override asin(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.asin(currentValue);
+
+ if (Number.isNaN(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override asinh(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.asinh(currentValue);
+
+ if (Number.isNaN(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override tan(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.tan(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override tanh(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.tanh(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override atan(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.atan(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override atan2(valueObject: BaseValueObject): BaseValueObject {
+ if (valueObject.isArray()) {
+ return valueObject.atan2Inverse(this);
+ }
+
+ const currentValue = this.getValue();
+ const value = valueObject.getValue();
+
+ if (typeof value === 'string') {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ if (typeof value === 'number') {
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.atan2(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+ if (typeof value === 'boolean') {
+ return new NumberValueObject(Math.atan2(currentValue, value ? 1 : 0));
+ }
+
+ return this;
+ }
+
+ override atanh(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.atanh(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override log(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (typeof currentValue === 'number' && currentValue <= 0) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.log(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(Math.sin(currentValue));
+
+ return new NumberValueObject(result);
}
override log10(): BaseValueObject {
@@ -523,10 +910,49 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.NUM);
}
- if (Math.abs(currentValue) === Infinity) {
- return new NumberValueObject(Infinity);
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.log10(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+
+ override exp(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.exp(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(log10(currentValue));
+
+ return new NumberValueObject(result);
+ }
+
+ override abs(): BaseValueObject {
+ const currentValue = this.getValue();
+
+ if (!Number.isFinite(currentValue)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = Math.abs(currentValue);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
}
override round(valueObject: BaseValueObject): BaseValueObject {
@@ -541,10 +967,17 @@ export class NumberValueObject extends BaseValueObject {
return ErrorValueObject.create(ErrorType.VALUE);
}
if (typeof value === 'number') {
- if (Math.abs(currentValue) === Infinity || Math.abs(value) === Infinity) {
- return new NumberValueObject(Infinity);
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = round(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
}
- return new NumberValueObject(round(currentValue, value));
+
+ return new NumberValueObject(result);
}
if (typeof value === 'boolean') {
return new NumberValueObject(round(currentValue, value ? 1 : 0));
@@ -553,6 +986,68 @@ export class NumberValueObject extends BaseValueObject {
return this;
}
+ override floor(valueObject: BaseValueObject): BaseValueObject {
+ if (valueObject.isArray()) {
+ return valueObject.floorInverse(this);
+ }
+
+ const currentValue = this.getValue();
+ const value = valueObject.getValue();
+
+ if (typeof value === 'string') {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ if (typeof value === 'number') {
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = floor(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+ if (typeof value === 'boolean') {
+ return new NumberValueObject(floor(currentValue, value ? 1 : 0));
+ }
+
+ return this;
+ }
+
+ override ceil(valueObject: BaseValueObject): BaseValueObject {
+ if (valueObject.isArray()) {
+ return valueObject.ceilInverse(this);
+ }
+
+ const currentValue = this.getValue();
+ const value = valueObject.getValue();
+
+ if (typeof value === 'string') {
+ return ErrorValueObject.create(ErrorType.VALUE);
+ }
+ if (typeof value === 'number') {
+ if (!Number.isFinite(currentValue) || !Number.isFinite(value)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ const result = ceil(currentValue, value);
+
+ if (!Number.isFinite(result)) {
+ return ErrorValueObject.create(ErrorType.NUM);
+ }
+
+ return new NumberValueObject(result);
+ }
+ if (typeof value === 'boolean') {
+ return new NumberValueObject(ceil(currentValue, value ? 1 : 0));
+ }
+
+ return this;
+ }
+
private _compareInfinity(currentValue: number, value: number, operator: compareToken) {
let result = false;
switch (operator) {