New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mathjslab

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mathjslab - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

lib/src/configuration.d.ts

4

CHANGES.md

@@ -5,2 +5,6 @@ # Release notes

## 1.2.3
- The file 'configuration.ts' and 'configuration.spec.ts' has been created. Two user functions (configure and getconfig) was created to manage internal configurations of MathJSLab. Most of the settings refer to Decimal.js settings related to the accuracy of the results.
- Namespaces wrapping external definitions in 'evaluator.ts' and 'complex-decimal.ts' files.
## 1.2.2

@@ -7,0 +11,0 @@ - Bug fix in function 'cat'.

19

CONTRIBUTING.md

@@ -72,3 +72,3 @@ # Contributing to MathJSLab

* We ALWAYS put spaces after list items and method parameters (`[1, 2, 3]`, not `[1,2,3]`), around operators (`x += 1`, not `x+=1`), and around hash arrows.
* Prefer the object spread operator (`{...anotherObj}`) to `Object.assign()`.
* Prefer the `Object.assign()` to object spread operator (`{...anotherObj}`).
* Inline exports with expressions whenever possible:

@@ -91,3 +91,5 @@ ```typescript

The MathJSLab project started almost a decade ago, but it is still in its infancy. There are several work fronts, some already open, others yet to begin, none yet completed.
The MathJSLab project started almost a decade ago, but it is still in its
infancy. There are several work fronts, some already open, others yet to
begin, none yet completed.

@@ -99,7 +101,4 @@ Some are listed below:

definitions of each function in terms of the real and imaginary parts.
* Only one single ComplexDecimal type based on Decimal.js is implemented.
Extend to support ComplexDecimal type based on common javascript number type.
It is necessary for faster and more efficient computing.
* Use Web Workers and/or WebAssembly for more efficient computing. The complete
evaluator can reside in a Web Worker.
* All operations over array elements are complex. Create and use real
operations for arrays with only real elements.
* Parser is designed to scan a line. Need to code a parser that scan multiple

@@ -116,5 +115,7 @@ lines calling Evaluator when need.

[ES6](https://262.ecma-international.org/6.0/) modules written in
[Typescript](https://www.typescriptlang.org/).
[Typescript](https://www.typescriptlang.org/). This is the reason why
MathJSLab is compiled as an ES5 module.
You are welcome to contribute to this project. I will be very grateful if you participate in some way.
You are welcome to contribute to this project. I will be very grateful if you
participate in some way.

@@ -121,0 +122,0 @@ Thanks,

@@ -9,4 +9,5 @@ export declare class CharString {

static unparse(value: CharString): string;
unparse(): string;
static unparseMathML(value: CharString): string;
static removeQuotes(value: CharString): CharString;
}
import { Decimal } from 'decimal.js';
export declare namespace ComplexDecimal {
type Rounding = Decimal.Rounding;
type Modulo = Decimal.Modulo;
type ComplexDecimalConfig = {
/**
* The maximum number of significant digits of the result of an operation.
* Values equal to or greater than 336 is used to produce correct rounding of
* trigonometric, hyperbolic and exponential functions.
*/
precision?: number;
/**
* Number of significant digits to reduce precision before compare operations and
* unparse.
*/
precisionCompare?: number;
/**
* The default rounding mode used when rounding the result of an operation to
* precision significant digits.
*/
rounding?: Rounding;
/**
* The positive exponent value at and above which unparse returns exponential
* notation.
*/
toExpPos?: number;
/**
* The negative exponent limit, i.e. the exponent value below which underflow
* to zero occurs.
*/
minE?: number;
/**
* The positive exponent limit, i.e. the exponent value above which overflow
* to Infinity occurs.
*/
maxE?: number;
/**
* The negative exponent value at and below which unparse returns exponential
* notation.
*/
toExpNeg?: number;
/**
* The modulo mode used when calculating the modulus: a mod n.
*/
modulo?: Decimal.Modulo;
/**
* The value that determines whether cryptographically-secure
* pseudo-random number generation is used.
*/
crypto?: boolean;
};
/**
* Binary operations name type.
*/
type TBinaryOperationName = 'add' | 'sub' | 'mul' | 'rdiv' | 'ldiv' | 'power' | 'lt' | 'le' | 'eq' | 'ge' | 'gt' | 'ne' | 'and' | 'or' | 'xor' | 'mod' | 'rem' | 'minWise' | 'maxWise';
/**
* Unary operations name type.
*/
type TUnaryOperationLeftName = 'copy' | 'neg' | 'not';
}
/**
* Binary operations name type.
*/
export type TBinaryOperationName = 'add' | 'sub' | 'mul' | 'rdiv' | 'ldiv' | 'power' | 'lt' | 'le' | 'eq' | 'ge' | 'gt' | 'ne' | 'and' | 'or' | 'xor' | 'mod' | 'rem' | 'minWise' | 'maxWise';
/**
* Unary operations name type.
*/
export type TUnaryOperationLeftName = 'copy' | 'neg' | 'not';
/**
* # ComplexDecimal

@@ -19,3 +70,10 @@ *

export declare class ComplexDecimal {
static readonly defaultConfiguration: ComplexDecimal.ComplexDecimalConfig;
static get settings(): ComplexDecimal.ComplexDecimalConfig;
/**
*
* @param config
*/
static set(config: ComplexDecimal.ComplexDecimalConfig): void;
/**
* Functions with one argument (mappers)

@@ -94,2 +152,3 @@ */

static unparse(value: ComplexDecimal): string;
unparse(): string;
/**

@@ -96,0 +155,0 @@ * Unparse real or imaginary part.

import { ComplexDecimal } from './complex-decimal';
import { MultiArray } from './multi-array';
import { NodeReturnList } from './evaluator';
import { Evaluator } from './evaluator';
import { CharString } from './char-string';
export declare abstract class CoreFunctions {
static functions: {
[name: string]: Function;
};
static functions: Record<string, Function>;
/**

@@ -175,3 +173,3 @@ *

*/
static min(...args: any[]): MultiArray | NodeReturnList | undefined;
static min(...args: any[]): MultiArray | Evaluator.NodeReturnList | undefined;
/**

@@ -182,3 +180,3 @@ * Maximum elements of array.

*/
static max(...args: any[]): MultiArray | NodeReturnList | undefined;
static max(...args: any[]): MultiArray | Evaluator.NodeReturnList | undefined;
/**

@@ -198,3 +196,3 @@ * Base method of cummin and cummax user functions.

*/
static cummin(M: MultiArray, DIM?: MultiArray | ComplexDecimal): NodeReturnList;
static cummin(M: MultiArray, DIM?: MultiArray | ComplexDecimal): Evaluator.NodeReturnList;
/**

@@ -206,3 +204,3 @@ *

*/
static cummax(M: MultiArray, DIM?: MultiArray | ComplexDecimal): NodeReturnList;
static cummax(M: MultiArray, DIM?: MultiArray | ComplexDecimal): Evaluator.NodeReturnList;
/**

@@ -209,0 +207,0 @@ *

@@ -7,139 +7,141 @@ /**

import { MultiArray } from './multi-array';
/**
* Operator type.
*/
export type TOperator = '+' | '-' | '.*' | '*' | './' | '/' | '.\\' | '\\' | '.^' | '^' | '.**' | '**' | '<' | '<=' | '==' | '>=' | '>' | '!=' | '~=' | '&' | '|' | '&&' | '||' | '=' | '+=' | '-=' | '*=' | '/=' | '\\=' | '^=' | '**=' | '.*=' | './=' | '.\\=' | '.^=' | '.**=' | '&=' | '|=' | '()' | '!' | '~' | '+_' | '-_' | '++_' | '--_' | ".'" | "'" | '_++' | '_--';
/**
* aliasNameTable type.
*/
export type TAliasNameTable = Record<string, RegExp>;
/**
* baseFunctionTable type.
*/
export type TBaseFunctionTableEntry = {
mapper?: boolean;
ev: boolean[];
func: Function;
unparserMathML?: (tree: any) => string;
};
export type TBaseFunctionTable = Record<string, TBaseFunctionTableEntry>;
/**
* nameTable type.
*/
export type TNameTableEntry = {
args: Array<any>;
expr: any;
};
export type TNameTable = Record<string, TNameTableEntry>;
/**
* commandWordListTable type.
*/
export type TCommandWordListFunction = (...args: string[]) => void;
export type TCommandWordListTableEntry = {
func: TCommandWordListFunction;
};
export type TCommandWordListTable = Record<string, TCommandWordListTableEntry>;
/**
* TEvaluatorConfig type.
*/
export type TEvaluatorConfig = {
aliasTable?: TAliasNameTable;
externalFunctionTable?: TBaseFunctionTable;
externalCmdWListTable?: TCommandWordListTable;
};
/**
* AST (Abstract Syntax Tree) nodes.
*/
/**
* Common primary node.
*/
interface PrimaryNode {
type: string | number;
parent?: any;
index?: number;
export declare namespace Evaluator {
/**
* Operator type.
*/
type TOperator = '+' | '-' | '.*' | '*' | './' | '/' | '.\\' | '\\' | '.^' | '^' | '.**' | '**' | '<' | '<=' | '==' | '>=' | '>' | '!=' | '~=' | '&' | '|' | '&&' | '||' | '=' | '+=' | '-=' | '*=' | '/=' | '\\=' | '^=' | '**=' | '.*=' | './=' | '.\\=' | '.^=' | '.**=' | '&=' | '|=' | '()' | '!' | '~' | '+_' | '-_' | '++_' | '--_' | ".'" | "'" | '_++' | '_--';
/**
* aliasNameTable type.
*/
type TAliasNameTable = Record<string, RegExp>;
/**
* baseFunctionTable type.
*/
type TBaseFunctionTableEntry = {
mapper?: boolean;
ev: boolean[];
func: Function;
unparserMathML?: (tree: any) => string;
};
type TBaseFunctionTable = Record<string, TBaseFunctionTableEntry>;
/**
* nameTable type.
*/
type TNameTableEntry = {
args: Array<any>;
expr: any;
};
type TNameTable = Record<string, TNameTableEntry>;
/**
* commandWordListTable type.
*/
type TCommandWordListFunction = (...args: string[]) => void;
type TCommandWordListTableEntry = {
func: TCommandWordListFunction;
};
type TCommandWordListTable = Record<string, TCommandWordListTableEntry>;
/**
* TEvaluatorConfig type.
*/
type TEvaluatorConfig = {
aliasTable?: TAliasNameTable;
externalFunctionTable?: TBaseFunctionTable;
externalCmdWListTable?: TCommandWordListTable;
};
/**
* AST (Abstract Syntax Tree) nodes.
*/
/**
* Common primary node.
*/
interface PrimaryNode {
type: string | number;
parent?: any;
index?: number;
}
/**
* Expression node.
*/
type NodeExpr = NodeName | NodeArgExpr | NodeOperation | NodeList | NodeRange | NodeReturnList | MultiArray | ComplexDecimal;
/**
* Reserved node.
*/
interface NodeReserved extends PrimaryNode {
}
/**
* Name node.
*/
interface NodeName extends PrimaryNode {
type: 'NAME';
id: string;
}
/**
* Command word list node.
*/
interface NodeCmdWList extends PrimaryNode {
type: 'CmdWList';
id: string;
args: Array<CharString>;
}
/**
* Expression and arguments node.
*/
interface NodeArgExpr extends PrimaryNode {
type: 'ARG';
expr: NodeExpr;
args: Array<NodeExpr>;
}
/**
* Range node.
*/
interface NodeRange extends PrimaryNode {
type: 'RANGE';
start: NodeExpr | null;
stop: NodeExpr | null;
stride: NodeExpr | null;
}
/**
* Operation node.
*/
type NodeOperation = UnaryOperation | BinaryOperation;
/**
* Unary operation node.
*/
type UnaryOperation = UnaryOperationL | UnaryOperationR;
/**
* Right unary operation node.
*/
interface UnaryOperationR extends PrimaryNode {
right: NodeExpr;
}
/**
* Left unary operation node.
*/
interface UnaryOperationL extends PrimaryNode {
left: NodeExpr;
}
/**
* Binary operation.
*/
interface BinaryOperation extends PrimaryNode {
left: NodeExpr;
right: NodeExpr;
}
/**
* List node
*/
interface NodeList extends PrimaryNode {
type: 'LIST';
list: Array<NodeExpr>;
}
type ReturnSelector = (length: number, index: number) => any;
/**
* Return list node
*/
interface NodeReturnList extends PrimaryNode {
type: 'RETLIST';
selector: ReturnSelector;
}
}
/**
* Expression node.
*/
export type NodeExpr = NodeName | NodeArgExpr | NodeOperation | NodeList | NodeRange | NodeReturnList | MultiArray | ComplexDecimal;
/**
* Reserved node.
*/
interface NodeReserved extends PrimaryNode {
}
/**
* Name node.
*/
export interface NodeName extends PrimaryNode {
type: 'NAME';
id: string;
}
/**
* Command word list node.
*/
interface NodeCmdWList extends PrimaryNode {
type: 'CmdWList';
id: string;
args: Array<CharString>;
}
/**
* Expression and arguments node.
*/
export interface NodeArgExpr extends PrimaryNode {
type: 'ARG';
expr: NodeExpr;
args: Array<NodeExpr>;
}
/**
* Range node.
*/
interface NodeRange extends PrimaryNode {
type: 'RANGE';
start: NodeExpr | null;
stop: NodeExpr | null;
stride: NodeExpr | null;
}
/**
* Operation node.
*/
export type NodeOperation = UnaryOperation | BinaryOperation;
/**
* Unary operation node.
*/
type UnaryOperation = UnaryOperationL | UnaryOperationR;
/**
* Right unary operation node.
*/
interface UnaryOperationR extends PrimaryNode {
right: NodeExpr;
}
/**
* Left unary operation node.
*/
interface UnaryOperationL extends PrimaryNode {
left: NodeExpr;
}
/**
* Binary operation.
*/
interface BinaryOperation extends PrimaryNode {
left: NodeExpr;
right: NodeExpr;
}
/**
* List node
*/
export interface NodeList extends PrimaryNode {
type: 'LIST';
list: Array<NodeExpr>;
}
export type ReturnSelector = (length: number, index: number) => any;
/**
* Return list node
*/
export interface NodeReturnList extends PrimaryNode {
type: 'RETLIST';
selector: ReturnSelector;
}
/**
* External parser declarations (defined in parser body)

@@ -184,3 +186,3 @@ */

*/
nameTable: TNameTable;
nameTable: Evaluator.TNameTable;
readonlyNameTable: string[];

@@ -194,3 +196,3 @@ /**

*/
baseFunctionTable: TBaseFunctionTable;
baseFunctionTable: Evaluator.TBaseFunctionTable;
/**

@@ -207,3 +209,3 @@ * Get a list of names of defined functions in baseFunctionTable.

*/
commandWordListTable: TCommandWordListTable;
commandWordListTable: Evaluator.TCommandWordListTable;
/**

@@ -276,3 +278,3 @@ * Parser (generated by Jison).

*/
static initialize(config?: TEvaluatorConfig): Evaluator;
static initialize(config?: Evaluator.TEvaluatorConfig): Evaluator;
/**

@@ -308,3 +310,3 @@ * Alias name function. This property is set when running Evaluator.initialize.

*/
nodeReserved(nodeid: string): NodeReserved;
nodeReserved(nodeid: string): Evaluator.NodeReserved;
/**

@@ -315,3 +317,3 @@ * Create name node.

*/
nodeName(nodeid: string): NodeName;
nodeName(nodeid: string): Evaluator.NodeName;
/**

@@ -323,3 +325,3 @@ * Create command word list node.

*/
nodeCmdWList(nodename: NodeName, nodelist: NodeList): NodeCmdWList;
nodeCmdWList(nodename: Evaluator.NodeName, nodelist: Evaluator.NodeList): Evaluator.NodeCmdWList;
/**

@@ -331,3 +333,3 @@ * Create expression and arguments node.

*/
nodeArgExpr(nodeexpr: any, nodelist?: any): NodeArgExpr;
nodeArgExpr(nodeexpr: any, nodelist?: any): Evaluator.NodeArgExpr;
/**

@@ -340,3 +342,3 @@ * Create range node. If two arguments are passed then it is 'start' and

*/
nodeRange(...args: any): NodeRange;
nodeRange(...args: any): Evaluator.NodeRange;
/**

@@ -349,3 +351,3 @@ * Create operator node.

*/
nodeOp(op: TOperator, data1: any, data2?: any): NodeOperation;
nodeOp(op: Evaluator.TOperator, data1: any, data2?: any): Evaluator.NodeOperation;
/**

@@ -356,3 +358,3 @@ * Create first element of list node.

*/
nodeListFirst(node?: any): NodeList;
nodeListFirst(node?: any): Evaluator.NodeList;
/**

@@ -364,3 +366,3 @@ * Append node to list node.

*/
nodeList(lnode: NodeList, node: any): NodeList;
nodeList(lnode: Evaluator.NodeList, node: any): Evaluator.NodeList;
/**

@@ -371,3 +373,3 @@ * Create first row of a MultiArray.

*/
nodeFirstRow(row: NodeList): MultiArray;
nodeFirstRow(row: Evaluator.NodeList): MultiArray;
/**

@@ -379,3 +381,3 @@ * Append row to MultiArray.

*/
nodeAppendRow(M: MultiArray, row: NodeList): MultiArray;
nodeAppendRow(M: MultiArray, row: Evaluator.NodeList): MultiArray;
/**

@@ -386,3 +388,3 @@ * Creates NodeReturnList (multiple assignment)

*/
static nodeReturnList(selector: ReturnSelector): NodeReturnList;
static nodeReturnList(selector: Evaluator.ReturnSelector): Evaluator.NodeReturnList;
/**

@@ -480,2 +482,1 @@ * Throws error if left hand side length of multiple assignment greater

}
export {};

@@ -8,2 +8,3 @@ export { CharString } from './char-string';

export { MathObject } from './math-object';
export { TEvaluatorConfig, TBaseFunctionTable, NodeName, NodeExpr, Evaluator, TAliasNameTable } from './evaluator';
export { Configuration } from './configuration';
export { Evaluator } from './evaluator';

@@ -1,2 +0,2 @@

import { TBinaryOperationName, TUnaryOperationLeftName } from './complex-decimal';
import { ComplexDecimal } from './complex-decimal';
export declare abstract class MathObject {

@@ -13,4 +13,4 @@ static unaryOpFunction: {

static copy(right: any): any;
static elementWiseOperation(op: TBinaryOperationName, left: any, right: any): any;
static leftOperation(op: TUnaryOperationLeftName, right: any): any;
static elementWiseOperation(op: ComplexDecimal.TBinaryOperationName, left: any, right: any): any;
static leftOperation(op: ComplexDecimal.TUnaryOperationLeftName, right: any): any;
static plus(left: any, right: any): any;

@@ -17,0 +17,0 @@ static minus(left: any, right: any): any;

@@ -1,3 +0,3 @@

import { ComplexDecimal, TBinaryOperationName, TUnaryOperationLeftName } from './complex-decimal';
import { Evaluator, TNameTable } from './evaluator';
import { ComplexDecimal } from './complex-decimal';
import { Evaluator } from './evaluator';
/**

@@ -309,3 +309,3 @@ * # MultiArray

*/
static scalarOpMultiArray(op: TBinaryOperationName, left: ComplexDecimal, right: MultiArray): MultiArray;
static scalarOpMultiArray(op: ComplexDecimal.TBinaryOperationName, left: ComplexDecimal, right: MultiArray): MultiArray;
/**

@@ -318,3 +318,3 @@ * Binary operation 'array `operation` scalar'.

*/
static MultiArrayOpScalar(op: TBinaryOperationName, left: MultiArray, right: ComplexDecimal): MultiArray;
static MultiArrayOpScalar(op: ComplexDecimal.TBinaryOperationName, left: MultiArray, right: ComplexDecimal): MultiArray;
/**

@@ -326,3 +326,3 @@ * Unary left operation.

*/
static leftOperation(op: TUnaryOperationLeftName, right: MultiArray): MultiArray;
static leftOperation(op: ComplexDecimal.TUnaryOperationLeftName, right: MultiArray): MultiArray;
/**

@@ -335,3 +335,3 @@ * Binary element-wise operatior.

*/
static elementWiseOperation(op: TBinaryOperationName, left: MultiArray, right: MultiArray): MultiArray;
static elementWiseOperation(op: ComplexDecimal.TBinaryOperationName, left: MultiArray, right: MultiArray): MultiArray;
/**

@@ -430,3 +430,3 @@ * Calls a defined callback function on each element of an MultiArray,

*/
static setElements(nameTable: TNameTable, id: string, indexList: (ComplexDecimal | MultiArray)[], right: MultiArray, input?: string, that?: Evaluator): void;
static setElements(nameTable: Evaluator.TNameTable, id: string, indexList: (ComplexDecimal | MultiArray)[], right: MultiArray, input?: string, that?: Evaluator): void;
/**

@@ -439,3 +439,3 @@ * Set selected items from MultiArray by logical indexing.

*/
static setElementsLogical(nameTable: TNameTable, id: string, arg: ComplexDecimal[], right: MultiArray): void;
static setElementsLogical(nameTable: Evaluator.TNameTable, id: string, arg: ComplexDecimal[], right: MultiArray): void;
}
{
"name": "mathjslab",
"version": "1.2.2",
"version": "1.2.3",
"description": "MathJSLab - An interpreter with language syntax like MATLAB®/Octave. ISBN 978-65-00-82338-7",

@@ -5,0 +5,0 @@ "main": "lib/mathjslab.js",

@@ -155,3 +155,7 @@ # MathJSLab

* Parsing is executed line-by-line.
* There are only one a complex numeric type. Other implemented types is boolean and character string;
* There are only one a complex numeric type. Other implemented types is
boolean and character string. Character strings are treated differently than
in MATLAB&reg;/Octave. An entire string can be placed as an element of an
array and operations with strings are not supported, nor are they converted
to numbers.

@@ -158,0 +162,0 @@ ## License

@@ -19,2 +19,5 @@ export class CharString {

}
public unparse(): string {
return this.str;
}
static unparseMathML(value: CharString): string {

@@ -21,0 +24,0 @@ return '<mn>' + value.str + '</mn>';

import { Decimal } from 'decimal.js';
/**
* decimal.js and ComplexDecimal configuration parameters.
*/
/* eslint-disable-next-line @typescript-eslint/no-namespace */
export namespace ComplexDecimal {
export type Rounding = Decimal.Rounding;
/**
* The maximum number of significant digits of the result of an operation.
* Values equal to or greater than 336 is used to produce correct rounding of
* trigonometric, hyperbolic and exponential functions.
*/
const DecimalPrecision = 336;
export type Modulo = Decimal.Modulo;
/**
* Number of significant digits to reduce precision in compare operations and
* unparse.
*/
const DecimalPrecisionCompare = 7;
export type ComplexDecimalConfig = {
/**
* The maximum number of significant digits of the result of an operation.
* Values equal to or greater than 336 is used to produce correct rounding of
* trigonometric, hyperbolic and exponential functions.
*/
precision?: number;
/**
* Number of significant digits to reduce precision before compare operations and
* unparse.
*/
precisionCompare?: number;
/**
* The default rounding mode used when rounding the result of an operation to
* precision significant digits.
*/
rounding?: Rounding;
/**
* The positive exponent value at and above which unparse returns exponential
* notation.
*/
toExpPos?: number;
/**
* The negative exponent limit, i.e. the exponent value below which underflow
* to zero occurs.
*/
minE?: number;
/**
* The positive exponent limit, i.e. the exponent value above which overflow
* to Infinity occurs.
*/
maxE?: number;
/**
* The negative exponent value at and below which unparse returns exponential
* notation.
*/
toExpNeg?: number;
/**
* The modulo mode used when calculating the modulus: a mod n.
*/
modulo?: Decimal.Modulo;
/**
* The value that determines whether cryptographically-secure
* pseudo-random number generation is used.
*/
crypto?: boolean;
};
/**
* The default rounding mode used when rounding the result of an operation to
* precision significant digits.
*/
const DecimalRounding = Decimal.ROUND_HALF_DOWN;
/**
* Binary operations name type.
*/
export type TBinaryOperationName =
| 'add'
| 'sub'
| 'mul'
| 'rdiv'
| 'ldiv'
| 'power'
| 'lt'
| 'le'
| 'eq'
| 'ge'
| 'gt'
| 'ne'
| 'and'
| 'or'
| 'xor'
| 'mod'
| 'rem'
| 'minWise'
| 'maxWise';
/**
* The positive exponent value at and above which toString returns exponential
* notation.
*/
const DecimaltoExpPos = 20;
/**
* Unary operations name type.
*/
export type TUnaryOperationLeftName = 'copy' | 'neg' | 'not';
}
/**
* The negative exponent value at and below which toString returns exponential
* notation.
*/
const DecimaltoExpNeg = -7;
const ComplexDecimalConfig: ComplexDecimal.ComplexDecimalConfig = {
precision: 336,
precisionCompare: 7,
rounding: Decimal.ROUND_HALF_DOWN,
toExpPos: 20,
toExpNeg: -7,
minE: -9e15,
maxE: 9e15,
modulo: Decimal.ROUND_DOWN,
crypto: false,
};
/**
* decimal.js setup.
*/
Decimal.set({
precision: DecimalPrecision,
rounding: DecimalRounding,
toExpNeg: DecimaltoExpNeg,
toExpPos: DecimaltoExpPos,
});
const defaultComplexDecimalConfig = Object.assign({}, ComplexDecimalConfig);
/**
* Binary operations name type.
*/
export type TBinaryOperationName =
| 'add'
| 'sub'
| 'mul'
| 'rdiv'
| 'ldiv'
| 'power'
| 'lt'
| 'le'
| 'eq'
| 'ge'
| 'gt'
| 'ne'
| 'and'
| 'or'
| 'xor'
| 'mod'
| 'rem'
| 'minWise'
| 'maxWise';
/**
* Unary operations name type.
*/
export type TUnaryOperationLeftName = 'copy' | 'neg' | 'not';
/**
* # ComplexDecimal

@@ -86,3 +110,47 @@ *

export class ComplexDecimal {
public static readonly defaultConfiguration = defaultComplexDecimalConfig;
public static get settings() {
return ComplexDecimalConfig;
}
/**
*
* @param config
*/
public static set(config: ComplexDecimal.ComplexDecimalConfig): void {
const decimal: Decimal.Config = {};
if (typeof config.precision !== 'undefined') {
ComplexDecimalConfig.precision = decimal.precision = config.precision;
}
if (typeof config.rounding !== 'undefined') {
ComplexDecimalConfig.rounding = decimal.rounding = config.rounding;
}
if (typeof config.toExpPos !== 'undefined') {
ComplexDecimalConfig.toExpPos = decimal.toExpPos = config.toExpPos;
}
if (typeof config.toExpNeg !== 'undefined') {
ComplexDecimalConfig.toExpNeg = decimal.toExpNeg = config.toExpNeg;
}
if (typeof config.minE !== 'undefined') {
ComplexDecimalConfig.minE = decimal.minE = config.minE;
}
if (typeof config.maxE !== 'undefined') {
ComplexDecimalConfig.maxE = decimal.maxE = config.maxE;
}
if (typeof config.modulo !== 'undefined') {
ComplexDecimalConfig.modulo = decimal.modulo = config.modulo;
}
if (typeof config.crypto !== 'undefined') {
ComplexDecimalConfig.crypto = decimal.crypto = config.crypto;
}
if (typeof config.precisionCompare !== 'undefined') {
ComplexDecimalConfig.precisionCompare = config.precisionCompare;
}
if (Object.keys(decimal).length > 0) {
Decimal.set(decimal);
}
}
/**
* Functions with one argument (mappers)

@@ -310,2 +378,6 @@ */

public unparse(): string {
return ComplexDecimal.unparse(this);
}
/**

@@ -385,3 +457,5 @@ * Unparse real or imaginary part.

private static toMaxPrecisionDecimal(value: Decimal): Decimal {
return value.toSignificantDigits(Decimal.precision - DecimalPrecisionCompare).toDecimalPlaces(Decimal.precision - DecimalPrecisionCompare);
return value
.toSignificantDigits(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number))
.toDecimalPlaces(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number));
}

@@ -396,4 +470,8 @@

return new ComplexDecimal(
value.re.toSignificantDigits(Decimal.precision - DecimalPrecisionCompare).toDecimalPlaces(Decimal.precision - DecimalPrecisionCompare),
value.im.toSignificantDigits(Decimal.precision - DecimalPrecisionCompare).toDecimalPlaces(Decimal.precision - DecimalPrecisionCompare),
value.re
.toSignificantDigits(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number))
.toDecimalPlaces(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number)),
value.im
.toSignificantDigits(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number))
.toDecimalPlaces(Decimal.precision - (ComplexDecimalConfig.precisionCompare as number)),
);

@@ -408,3 +486,3 @@ }

private static epsilonDecimal(): Decimal {
return Decimal.pow(10, -Decimal.precision + DecimalPrecisionCompare);
return Decimal.pow(10, -Decimal.precision + (ComplexDecimalConfig.precisionCompare as number));
}

@@ -1626,1 +1704,6 @@

}
/**
* Initial setup.
*/
ComplexDecimal.set(defaultComplexDecimalConfig);

@@ -1,8 +0,8 @@

import { ComplexDecimal, TBinaryOperationName } from './complex-decimal';
import { ComplexDecimal } from './complex-decimal';
import { MultiArray } from './multi-array';
import { Evaluator, NodeReturnList } from './evaluator';
import { Evaluator } from './evaluator';
import { CharString } from './char-string';
export abstract class CoreFunctions {
public static functions: { [name: string]: Function } = {
public static functions: Record<string, Function> = {
ndims: CoreFunctions.ndims,

@@ -330,3 +330,3 @@ rows: CoreFunctions.rows,

public static rand(...dimension: (MultiArray | ComplexDecimal)[]): MultiArray | ComplexDecimal {
return CoreFunctions.newFilledEach((n: number) => new ComplexDecimal(Math.random()), ...dimension);
return CoreFunctions.newFilledEach(() => new ComplexDecimal(Math.random()), ...dimension);
}

@@ -361,5 +361,3 @@

return CoreFunctions.newFilledEach(
imin === 0
? (n: number) => new ComplexDecimal(Math.round(imax * Math.random()))
: (n: number) => new ComplexDecimal(Math.round((imax - imin) * Math.random() + imin)),
imin === 0 ? () => new ComplexDecimal(Math.round(imax * Math.random())) : () => new ComplexDecimal(Math.round((imax - imin) * Math.random() + imin)),
...dimension,

@@ -464,3 +462,3 @@ );

*/
private static minMax(op: 'min' | 'max', ...args: any[]): MultiArray | NodeReturnList | undefined {
private static minMax(op: 'min' | 'max', ...args: any[]): MultiArray | Evaluator.NodeReturnList | undefined {
const minMaxAlogDimension = (M: MultiArray, dimension: number) => {

@@ -490,3 +488,3 @@ const reduced = MultiArray.reduceToArray(dimension, M);

// Broadcast
return MultiArray.elementWiseOperation((op + 'Wise') as TBinaryOperationName, MultiArray.scalarToMultiArray(args[0]), args[1]);
return MultiArray.elementWiseOperation((op + 'Wise') as ComplexDecimal.TBinaryOperationName, MultiArray.scalarToMultiArray(args[0]), args[1]);
case 3:

@@ -509,3 +507,3 @@ // Along selected dimension.

*/
public static min(...args: any[]): MultiArray | NodeReturnList | undefined {
public static min(...args: any[]): MultiArray | Evaluator.NodeReturnList | undefined {
return CoreFunctions.minMax('min', ...args);

@@ -519,3 +517,3 @@ }

*/
public static max(...args: any[]): MultiArray | NodeReturnList | undefined {
public static max(...args: any[]): MultiArray | Evaluator.NodeReturnList | undefined {
return CoreFunctions.minMax('max', ...args);

@@ -531,3 +529,3 @@ }

*/
private static cumMinMax(op: 'min' | 'max', M: MultiArray | ComplexDecimal, DIM?: MultiArray | ComplexDecimal): NodeReturnList {
private static cumMinMax(op: 'min' | 'max', M: MultiArray | ComplexDecimal, DIM?: MultiArray | ComplexDecimal): Evaluator.NodeReturnList {
const dim = DIM ? MultiArray.firstElement(DIM).re.toNumber() - 1 : 1;

@@ -563,3 +561,3 @@ M = MultiArray.scalarToMultiArray(M);

*/
public static cummin(M: MultiArray, DIM?: MultiArray | ComplexDecimal): NodeReturnList {
public static cummin(M: MultiArray, DIM?: MultiArray | ComplexDecimal): Evaluator.NodeReturnList {
return CoreFunctions.cumMinMax('min', M, DIM);

@@ -574,3 +572,3 @@ }

*/
public static cummax(M: MultiArray, DIM?: MultiArray | ComplexDecimal): NodeReturnList {
public static cummax(M: MultiArray, DIM?: MultiArray | ComplexDecimal): Evaluator.NodeReturnList {
return CoreFunctions.cumMinMax('max', M, DIM);

@@ -577,0 +575,0 @@ }

@@ -8,2 +8,3 @@ export { CharString } from './char-string';

export { MathObject } from './math-object';
export { TEvaluatorConfig, TBaseFunctionTable, NodeName, NodeExpr, Evaluator, TAliasNameTable } from './evaluator';
export { Configuration } from './configuration';
export { Evaluator } from './evaluator';

@@ -1,2 +0,2 @@

import { ComplexDecimal, TBinaryOperationName, TUnaryOperationLeftName } from './complex-decimal';
import { ComplexDecimal } from './complex-decimal';
import { MultiArray } from './multi-array';

@@ -48,3 +48,3 @@ import { LinearAlgebra } from './linear-algebra';

public static elementWiseOperation(op: TBinaryOperationName, left: any, right: any): any {
public static elementWiseOperation(op: ComplexDecimal.TBinaryOperationName, left: any, right: any): any {
if ('re' in left && 're' in right) {

@@ -61,3 +61,3 @@ return ComplexDecimal[op](left, right);

public static leftOperation(op: TUnaryOperationLeftName, right: any): any {
public static leftOperation(op: ComplexDecimal.TUnaryOperationLeftName, right: any): any {
if ('re' in right) {

@@ -64,0 +64,0 @@ return ComplexDecimal[op](right);

@@ -1,3 +0,3 @@

import { ComplexDecimal, TBinaryOperationName, TUnaryOperationLeftName } from './complex-decimal';
import { Evaluator, TNameTable } from './evaluator';
import { ComplexDecimal } from './complex-decimal';
import { Evaluator } from './evaluator';

@@ -736,3 +736,3 @@ /**

*/
public static scalarOpMultiArray(op: TBinaryOperationName, left: ComplexDecimal, right: MultiArray): MultiArray {
public static scalarOpMultiArray(op: ComplexDecimal.TBinaryOperationName, left: ComplexDecimal, right: MultiArray): MultiArray {
const result = new MultiArray(right.dimension);

@@ -751,3 +751,3 @@ result.array = right.array.map((row) => row.map((value) => ComplexDecimal[op](left, value)));

*/
public static MultiArrayOpScalar(op: TBinaryOperationName, left: MultiArray, right: ComplexDecimal): MultiArray {
public static MultiArrayOpScalar(op: ComplexDecimal.TBinaryOperationName, left: MultiArray, right: ComplexDecimal): MultiArray {
const result = new MultiArray(left.dimension);

@@ -765,3 +765,3 @@ result.array = left.array.map((row) => row.map((value) => ComplexDecimal[op](value, right)));

*/
public static leftOperation(op: TUnaryOperationLeftName, right: MultiArray): MultiArray {
public static leftOperation(op: ComplexDecimal.TUnaryOperationLeftName, right: MultiArray): MultiArray {
const result = new MultiArray(right.dimension);

@@ -780,3 +780,3 @@ result.array = right.array.map((row) => row.map((value) => ComplexDecimal[op](value)));

*/
public static elementWiseOperation(op: TBinaryOperationName, left: MultiArray, right: MultiArray): MultiArray {
public static elementWiseOperation(op: ComplexDecimal.TBinaryOperationName, left: MultiArray, right: MultiArray): MultiArray {
let leftDimension = left.dimension.slice();

@@ -1114,3 +1114,3 @@ let rightDimension = right.dimension.slice();

*/
public static setElements(nameTable: TNameTable, id: string, indexList: (ComplexDecimal | MultiArray)[], right: MultiArray, input?: string, that?: Evaluator): void {
public static setElements(nameTable: Evaluator.TNameTable, id: string, indexList: (ComplexDecimal | MultiArray)[], right: MultiArray, input?: string, that?: Evaluator): void {
if (indexList.length === 0) {

@@ -1172,3 +1172,3 @@ throw new RangeError('invalid empty index list.');

*/
public static setElementsLogical(nameTable: TNameTable, id: string, arg: ComplexDecimal[], right: MultiArray): void {
public static setElementsLogical(nameTable: Evaluator.TNameTable, id: string, arg: ComplexDecimal[], right: MultiArray): void {
const linright = MultiArray.linearize(right);

@@ -1175,0 +1175,0 @@ const test = arg.map((value: ComplexDecimal) => value.re.toNumber());

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc