name:
src/main/js/formulas/math/SIGN.ts
-rw-r--r--
905
1import { F7Exception } from "../../errors/F7Exception";
2import { SheetColumnRowKey } from "../../models/common/SheetColumnRowKey";
3import { Complex } from "../../models/common/Types";
4import { Converters } from "../../utils/Converters";
5import { Numbers } from "../../utils/Numbers";
6import { AbstractFormula } from "../AbstractFormula";
7import { FormulaName } from "../FormulaName";
8
9export class SIGN extends AbstractFormula {
10 static SELF: SIGN = new SIGN();
11 NAME = FormulaName.SIGN;
12
13 internal(origin: SheetColumnRowKey, ...values: Array<Complex>) {
14 AbstractFormula.checkLength(values.length, 1, this.NAME);
15 const value = Converters.first(this.collateralLookup(origin, values[0]));
16 if (value instanceof F7Exception) {
17 return value;
18 }
19 const number = Converters.toNumber(value);
20 if (Numbers.isZero(number)) {
21 return 0;
22 }
23 return number > 0 ? 1 : -1;
24 }
25}