UNPKG

@eagleoutice/flowr-dev

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

203 lines (202 loc) 7.34 kB
import type { BuiltInEvalHandlerArgs } from '../../environments/built-in'; import { type Value } from '../values/r-value'; /** R breaks a tie to the even neighbor, unlike `Math.round`, which always goes up */ declare function roundHalfEven(x: number, digits?: number): number; /** R rounds `%%` and `%/%` towards `-Inf`, unlike the JS `%` */ declare function mod(a: number, b: number): number; /** * One entry of the {@link NumericFns} registry: the parameters R declares, in order, and how to fold them. * * A call supplies its arguments positionally or under these names, and `fold` receives them in declaration * order, so a parameter R gives a default is simply an optional parameter of `fold`. Whatever `fold` cannot * answer (a missing operand it needs, a domain error) it returns `undefined` for, which keeps the call `Top`. */ export interface NumericFn { /** the parameter names, in the order R declares them; an argument matching none of them stops the fold */ readonly params: readonly string[]; /** the fold over the supplied operands, in declaration order */ readonly fold: (...args: number[]) => number | undefined; } /** * Every numeric built-in the value solver folds, operators included: `-` is an entry like `sqrt` is, and both * are reached through {@link resolveAsNumeric}. Teaching flowR one more is a line here plus the matching * `evalHandler` in the built-in configuration -- a test checks that the two agree. * * An operator gets its operands under the names R gives them (`e1`, `e2`), and the ones that also exist as a * unary form declare `e2` as optional. Anything the fold hands back that is not a finite number stays `Top`, * so `sqrt(-1)` or `1/0` need no special case here. */ export declare const NumericFns: { readonly '+': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b?: number) => number; }; readonly '-': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b?: number) => number; }; readonly '*': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b: number) => number; }; readonly '/': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b: number) => number; }; readonly '^': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b: number) => number; }; readonly '**': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b: number) => number; }; readonly '%%': { readonly params: readonly ["e1", "e2"]; readonly fold: typeof mod; }; readonly '%/%': { readonly params: readonly ["e1", "e2"]; readonly fold: (a: number, b: number) => number; }; readonly abs: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly sqrt: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly floor: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly ceiling: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly trunc: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly sign: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly round: { readonly params: readonly ["x", "digits"]; readonly fold: typeof roundHalfEven; }; readonly signif: { readonly params: readonly ["x", "digits"]; readonly fold: (x: number, digits?: number) => number | undefined; }; readonly exp: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly expm1: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly log: { readonly params: readonly ["x", "base"]; readonly fold: (x: number, base?: number) => number; }; readonly log2: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly log10: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly log1p: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly sin: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly cos: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly tan: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly asin: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly acos: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly atan: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly atan2: { readonly params: readonly ["y", "x"]; readonly fold: (y: number, x: number) => number; }; readonly sinh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly cosh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly tanh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly asinh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly acosh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly atanh: { readonly params: readonly ["x"]; readonly fold: (x: number) => number; }; readonly bitwAnd: { readonly params: readonly ["a", "b"]; readonly fold: (a: number, b: number) => number; }; readonly bitwOr: { readonly params: readonly ["a", "b"]; readonly fold: (a: number, b: number) => number; }; readonly bitwXor: { readonly params: readonly ["a", "b"]; readonly fold: (a: number, b: number) => number; }; readonly bitwNot: { readonly params: readonly ["a"]; readonly fold: (a: number) => number; }; readonly bitwShiftL: { readonly params: readonly ["a", "n"]; readonly fold: (a: number, n: number) => number; }; readonly bitwShiftR: { readonly params: readonly ["a", "n"]; readonly fold: (a: number, n: number) => number; }; }; /** * Resolves any call of a {@link NumericFns} entry to a {@link Value}: the operators in prefix or infix form, * the unary `+`/`-`, and the named functions with their arguments in any order R accepts. An operand may be a * number, a logical (counting as its `0`/`1`), or a vector of numbers, which folds elementwise. Anything that * does not resolve, a result that is not finite, and a vector length mismatch all stay `Top`. */ export declare function resolveAsNumeric(args: BuiltInEvalHandlerArgs): Value; export {};