MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / parse

Method parse

src/compute-engine/index.ts:1671–1714  ·  view source on GitHub ↗
(
    latex: string | null,
    options?: Partial<ParseLatexOptions> & {
      form?: FormOption;
      canonical?: CanonicalOptions;
      structural?: boolean;
    }
  )

Source from the content-addressed store, hash-verified

1669 * frame. Outside a frame the result is `Math.random` (live).
1670 */
1671 _substream(tag: number): RandomSubstream {
1672 return deriveSubstream(this._runtimeState.randomFrame, tag);
1673 }
1674
1675 /** Replace a number that is close to 0 with the exact integer 0.
1676 *
1677 * How close to 0 the number has to be to be considered 0 is determined by {@linkcode tolerance}.
1678 */
1679 chop(n: number): number;
1680 chop(n: BigDecimal): BigDecimal | 0;
1681 chop(n: Complex): Complex | 0;
1682 chop(n: number | BigDecimal | Complex): number | BigDecimal | Complex {
1683 const tolerance = this._numericConfiguration.tolerance;
1684 if (typeof n === 'number') {
1685 if (Math.abs(n) <= tolerance) return 0;
1686 return n;
1687 }
1688
1689 if (n instanceof BigDecimal) {
1690 if (n.isPositive() && n.lte(this._numericConfiguration.bignumTolerance))
1691 return 0;
1692 if (
1693 n.isNegative() &&
1694 n.gte(this._numericConfiguration.negBignumTolerance)
1695 )
1696 return 0;
1697 if (n.isZero()) return 0;
1698 return n;
1699 }
1700
1701 if (
1702 n instanceof Complex &&
1703 Math.abs(n.re) <= tolerance &&
1704 Math.abs(n.im) <= tolerance
1705 )
1706 return 0;
1707
1708 return n;
1709 }
1710
1711 /** Create an arbitrary precision number.
1712 *
1713 * The return value is an object with methods to perform arithmetic
1714 * operations:
1715 * - `toNumber()`: convert to a JavaScript `number` with potential loss of precision
1716 * - `add()`
1717 * - `sub()`

Callers 9

slowEvalFunction · 0.95
fastEvalFunction · 0.95
compiledEvalFunction · 0.95
identityFunction · 0.95
freshEngineFunction · 0.95
solvedFunction · 0.95
checkFunction · 0.95
normalizeIdentifierMethod · 0.95
outcomeFunction · 0.95

Calls 7

_requireLatexSyntaxMethod · 0.95
lookupDefinitionMethod · 0.95
isOperatorDefFunction · 0.90
isValueDefFunction · 0.90
boxFunction · 0.90
optionsToInternalFunction · 0.90
parseMethod · 0.65

Tested by 7

slowEvalFunction · 0.76
fastEvalFunction · 0.76
compiledEvalFunction · 0.76
identityFunction · 0.76
freshEngineFunction · 0.76
solvedFunction · 0.76
checkFunction · 0.76