nerdamer 1.1.13 → 2.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +184 -0
- package/README.md +293 -312
- package/dist/bundle.js +2 -0
- package/dist/bundle.js.LICENSE.txt +7 -0
- package/dist/parser.js +2 -0
- package/dist/parser.js.LICENSE.txt +7 -0
- package/docs-data/parser-functions.json +1960 -0
- package/index.d.ts +10 -426
- package/output/algebra/adapters.d.ts +33 -0
- package/output/algebra/adapters.js +109 -0
- package/output/algebra/algorithms/arith.d.ts +84 -0
- package/output/algebra/algorithms/arith.js +323 -0
- package/output/algebra/algorithms/factor.d.ts +3 -0
- package/output/algebra/algorithms/factor.js +5 -0
- package/output/algebra/algorithms/factorMultivariate.d.ts +23 -0
- package/output/algebra/algorithms/factorMultivariate.js +2393 -0
- package/output/algebra/algorithms/factorUnivariate.d.ts +72 -0
- package/output/algebra/algorithms/factorUnivariate.js +1072 -0
- package/output/algebra/algorithms/gcd.d.ts +22 -0
- package/output/algebra/algorithms/gcd.js +690 -0
- package/output/algebra/algorithms/groebnerBase.d.ts +157 -0
- package/output/algebra/algorithms/groebnerBase.js +1166 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.d.ts +137 -0
- package/output/algebra/algorithms/multiPoly/MultiPoly.js +346 -0
- package/output/algebra/algorithms/poly.d.ts +228 -0
- package/output/algebra/algorithms/poly.js +1299 -0
- package/output/algebra/algorithms/rational.d.ts +17 -0
- package/output/algebra/algorithms/rational.js +115 -0
- package/output/algebra/factor/factor.d.ts +62 -0
- package/output/algebra/factor/factor.js +158 -0
- package/output/algebra/gcd/gcd.d.ts +29 -0
- package/output/algebra/gcd/gcd.js +141 -0
- package/output/algebra/groebner.d.ts +21 -0
- package/output/algebra/groebner.js +42 -0
- package/output/algebra/partfrac.d.ts +19 -0
- package/output/algebra/partfrac.js +398 -0
- package/output/algebra/polynomialize.d.ts +20 -0
- package/output/algebra/polynomialize.js +24 -0
- package/output/algebra/simplify/complexsimp.d.ts +7 -0
- package/output/algebra/simplify/complexsimp.js +24 -0
- package/output/algebra/simplify/factorCommon.d.ts +13 -0
- package/output/algebra/simplify/factorCommon.js +136 -0
- package/output/algebra/simplify/funcsimp.d.ts +26 -0
- package/output/algebra/simplify/funcsimp.js +633 -0
- package/output/algebra/simplify/invtrigrewrite.d.ts +10 -0
- package/output/algebra/simplify/invtrigrewrite.js +96 -0
- package/output/algebra/simplify/ratsimp.d.ts +21 -0
- package/output/algebra/simplify/ratsimp.js +140 -0
- package/output/algebra/simplify/simplify.d.ts +25 -0
- package/output/algebra/simplify/simplify.js +228 -0
- package/output/algebra/simplify/trigreduce.d.ts +38 -0
- package/output/algebra/simplify/trigreduce.js +424 -0
- package/output/algebra/simplify/trigrewrite.d.ts +17 -0
- package/output/algebra/simplify/trigrewrite.js +156 -0
- package/output/algebra/simplify/trigsimp.d.ts +11 -0
- package/output/algebra/simplify/trigsimp.js +369 -0
- package/output/algebra/simplify/utils.d.ts +32 -0
- package/output/algebra/simplify/utils.js +56 -0
- package/output/algebra/utils.d.ts +32 -0
- package/output/algebra/utils.js +48 -0
- package/output/api/advanced.d.ts +7 -0
- package/output/api/advanced.js +18 -0
- package/output/api/algebra.d.ts +17 -0
- package/output/api/algebra.js +32 -0
- package/output/api/assumptions.d.ts +4 -0
- package/output/api/assumptions.js +11 -0
- package/output/api/calculus.d.ts +9 -0
- package/output/api/calculus.js +21 -0
- package/output/api/core.d.ts +17 -0
- package/output/api/core.js +41 -0
- package/output/api/debug.d.ts +16 -0
- package/output/api/debug.js +23 -0
- package/output/api/parser.d.ts +85 -0
- package/output/api/parser.js +16 -0
- package/output/api/solve.d.ts +10 -0
- package/output/api/solve.js +16 -0
- package/output/api/structures.d.ts +10 -0
- package/output/api/structures.js +22 -0
- package/output/calculus/derivative/diff.d.ts +30 -0
- package/output/calculus/derivative/diff.js +238 -0
- package/output/calculus/fresnel.d.ts +16 -0
- package/output/calculus/fresnel.js +39 -0
- package/output/calculus/integrate/byParts.d.ts +18 -0
- package/output/calculus/integrate/byParts.js +339 -0
- package/output/calculus/integrate/bySubstitution.d.ts +135 -0
- package/output/calculus/integrate/bySubstitution.js +411 -0
- package/output/calculus/integrate/integrate.d.ts +38 -0
- package/output/calculus/integrate/integrate.js +652 -0
- package/output/calculus/integrate/integrationTable.d.ts +2 -0
- package/output/calculus/integrate/integrationTable.js +914 -0
- package/output/calculus/integrate/utils.d.ts +28 -0
- package/output/calculus/integrate/utils.js +96 -0
- package/output/calculus/laplace/ilaplace.d.ts +31 -0
- package/output/calculus/laplace/ilaplace.js +192 -0
- package/output/calculus/laplace/ilaplaceTable.d.ts +2 -0
- package/output/calculus/laplace/ilaplaceTable.js +200 -0
- package/output/calculus/laplace/laplace.d.ts +22 -0
- package/output/calculus/laplace/laplace.js +109 -0
- package/output/calculus/laplace/laplaceTable.d.ts +2 -0
- package/output/calculus/laplace/laplaceTable.js +187 -0
- package/output/calculus/limit/limit.d.ts +35 -0
- package/output/calculus/limit/limit.js +1183 -0
- package/output/calculus/limit/limitsTable.d.ts +2 -0
- package/output/calculus/limit/limitsTable.js +7 -0
- package/output/core/Settings.d.ts +32 -0
- package/output/core/Settings.js +68 -0
- package/output/core/adapters.d.ts +18 -0
- package/output/core/adapters.js +40 -0
- package/output/core/classes/assumption/Assumption.d.ts +218 -0
- package/output/core/classes/assumption/Assumption.js +605 -0
- package/output/core/classes/assumption/assertiveFunctions.d.ts +6 -0
- package/output/core/classes/assumption/assertiveFunctions.js +64 -0
- package/output/core/classes/assumption/assume.d.ts +90 -0
- package/output/core/classes/assumption/assume.js +145 -0
- package/output/core/classes/collection/Collection.d.ts +107 -0
- package/output/core/classes/collection/Collection.js +231 -0
- package/output/core/classes/complex/Complex.d.ts +99 -0
- package/output/core/classes/complex/Complex.js +135 -0
- package/output/core/classes/decimalSet/DecimalSet.d.ts +226 -0
- package/output/core/classes/decimalSet/DecimalSet.js +453 -0
- package/output/core/classes/dictionary/Dictionary.d.ts +102 -0
- package/output/core/classes/dictionary/Dictionary.js +213 -0
- package/output/core/classes/equation/Equation.d.ts +256 -0
- package/output/core/classes/equation/Equation.js +350 -0
- package/output/core/classes/expression/CoeffObject.d.ts +100 -0
- package/output/core/classes/expression/CoeffObject.js +198 -0
- package/output/core/classes/expression/Expression.d.ts +1674 -0
- package/output/core/classes/expression/Expression.js +2332 -0
- package/output/core/classes/expression/analysis.d.ts +25 -0
- package/output/core/classes/expression/analysis.js +218 -0
- package/output/core/classes/expression/collect.d.ts +9 -0
- package/output/core/classes/expression/collect.js +49 -0
- package/output/core/classes/expression/format.d.ts +45 -0
- package/output/core/classes/expression/format.js +217 -0
- package/output/core/classes/expression/products.d.ts +23 -0
- package/output/core/classes/expression/products.js +115 -0
- package/output/core/classes/expression/shortcuts.d.ts +35 -0
- package/output/core/classes/expression/shortcuts.js +129 -0
- package/output/core/classes/expression/traversal.d.ts +31 -0
- package/output/core/classes/expression/traversal.js +216 -0
- package/output/core/classes/expression/trig.d.ts +25 -0
- package/output/core/classes/expression/trig.js +40 -0
- package/output/core/classes/expression/utils.d.ts +52 -0
- package/output/core/classes/expression/utils.js +189 -0
- package/output/core/classes/lookupTable/LookupTable.d.ts +12 -0
- package/output/core/classes/lookupTable/LookupTable.js +55 -0
- package/output/core/classes/matrix/Matrix.d.ts +227 -0
- package/output/core/classes/matrix/Matrix.js +889 -0
- package/output/core/classes/matrix/Sylvester.d.ts +11 -0
- package/output/core/classes/matrix/Sylvester.js +54 -0
- package/output/core/classes/matrix/functions.d.ts +26 -0
- package/output/core/classes/matrix/functions.js +52 -0
- package/output/core/classes/matrix/utils.d.ts +9 -0
- package/output/core/classes/matrix/utils.js +22 -0
- package/output/core/classes/parser/Parser.d.ts +480 -0
- package/output/core/classes/parser/Parser.js +1812 -0
- package/output/core/classes/parser/Token.d.ts +58 -0
- package/output/core/classes/parser/Token.js +137 -0
- package/output/core/classes/parser/constants.d.ts +160 -0
- package/output/core/classes/parser/constants.js +227 -0
- package/output/core/classes/parser/helpers.d.ts +21 -0
- package/output/core/classes/parser/helpers.js +42 -0
- package/output/core/classes/parser/operations/add.d.ts +15 -0
- package/output/core/classes/parser/operations/add.js +238 -0
- package/output/core/classes/parser/operations/comma.d.ts +7 -0
- package/output/core/classes/parser/operations/comma.js +11 -0
- package/output/core/classes/parser/operations/compare.d.ts +21 -0
- package/output/core/classes/parser/operations/compare.js +461 -0
- package/output/core/classes/parser/operations/divide.d.ts +2 -0
- package/output/core/classes/parser/operations/divide.js +72 -0
- package/output/core/classes/parser/operations/functions.d.ts +46 -0
- package/output/core/classes/parser/operations/functions.js +430 -0
- package/output/core/classes/parser/operations/multiply.d.ts +11 -0
- package/output/core/classes/parser/operations/multiply.js +321 -0
- package/output/core/classes/parser/operations/power.d.ts +48 -0
- package/output/core/classes/parser/operations/power.js +673 -0
- package/output/core/classes/parser/operations/subtract.d.ts +3 -0
- package/output/core/classes/parser/operations/subtract.js +35 -0
- package/output/core/classes/parser/preprocess.d.ts +14 -0
- package/output/core/classes/parser/preprocess.js +259 -0
- package/output/core/classes/parser/scripting/controlFlow.d.ts +121 -0
- package/output/core/classes/parser/scripting/controlFlow.js +355 -0
- package/output/core/classes/parser/scripting/evaluate.d.ts +10 -0
- package/output/core/classes/parser/scripting/evaluate.js +112 -0
- package/output/core/classes/parser/scripting/functions.d.ts +14 -0
- package/output/core/classes/parser/scripting/functions.js +59 -0
- package/output/core/classes/parser/scripting/scope.d.ts +35 -0
- package/output/core/classes/parser/scripting/scope.js +155 -0
- package/output/core/classes/parser/types.d.ts +125 -0
- package/output/core/classes/parser/types.js +2 -0
- package/output/core/classes/parser/wrappers/IndexedReference.d.ts +31 -0
- package/output/core/classes/parser/wrappers/IndexedReference.js +68 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.d.ts +24 -0
- package/output/core/classes/parser/wrappers/KeyValuePair.js +51 -0
- package/output/core/classes/polynomial/Polynomial.d.ts +500 -0
- package/output/core/classes/polynomial/Polynomial.js +1149 -0
- package/output/core/classes/polynomial/Term.d.ts +222 -0
- package/output/core/classes/polynomial/Term.js +430 -0
- package/output/core/classes/polynomial/functions.d.ts +69 -0
- package/output/core/classes/polynomial/functions.js +126 -0
- package/output/core/classes/polynomial/utils.d.ts +62 -0
- package/output/core/classes/polynomial/utils.js +206 -0
- package/output/core/classes/rational/Rational.d.ts +504 -0
- package/output/core/classes/rational/Rational.js +779 -0
- package/output/core/classes/seq/SEQ.d.ts +13 -0
- package/output/core/classes/seq/SEQ.js +137 -0
- package/output/core/classes/valuesSet/ValuesSet.d.ts +179 -0
- package/output/core/classes/valuesSet/ValuesSet.js +381 -0
- package/output/core/classes/vector/Vector.d.ts +222 -0
- package/output/core/classes/vector/Vector.js +497 -0
- package/output/core/classes/vector/functions.d.ts +28 -0
- package/output/core/classes/vector/functions.js +47 -0
- package/output/core/common/classes/MathematicalAggregate.d.ts +53 -0
- package/output/core/common/classes/MathematicalAggregate.js +140 -0
- package/output/core/common/classes/Scope.d.ts +62 -0
- package/output/core/common/classes/Scope.js +122 -0
- package/output/core/common/classes/StructuredEntity.d.ts +55 -0
- package/output/core/common/classes/StructuredEntity.js +151 -0
- package/output/core/common/common.d.ts +63 -0
- package/output/core/common/common.js +279 -0
- package/output/core/common/functions/functions.d.ts +14 -0
- package/output/core/common/functions/functions.js +33 -0
- package/output/core/common/functions/structuredEntityUtils.d.ts +27 -0
- package/output/core/common/functions/structuredEntityUtils.js +40 -0
- package/output/core/converters/BaseConverter.d.ts +97 -0
- package/output/core/converters/BaseConverter.js +405 -0
- package/output/core/converters/Converter.d.ts +111 -0
- package/output/core/converters/Converter.js +802 -0
- package/output/core/converters/Pattern.d.ts +71 -0
- package/output/core/converters/Pattern.js +302 -0
- package/output/core/dispatch.d.ts +34 -0
- package/output/core/dispatch.js +304 -0
- package/output/core/errors.d.ts +531 -0
- package/output/core/errors.js +621 -0
- package/output/core/functions/bigint/bigint.d.ts +121 -0
- package/output/core/functions/bigint/bigint.js +392 -0
- package/output/core/functions/bigint/primeFactor.d.ts +49 -0
- package/output/core/functions/bigint/primeFactor.js +267 -0
- package/output/core/functions/bigint/primes.d.ts +1 -0
- package/output/core/functions/bigint/primes.js +11 -0
- package/output/core/functions/build/definitions.d.ts +12 -0
- package/output/core/functions/build/definitions.js +133 -0
- package/output/core/functions/build/index.d.ts +32 -0
- package/output/core/functions/build/index.js +136 -0
- package/output/core/functions/complex.d.ts +90 -0
- package/output/core/functions/complex.js +482 -0
- package/output/core/functions/decimal.d.ts +24 -0
- package/output/core/functions/decimal.js +664 -0
- package/output/core/functions/expand/expand.d.ts +42 -0
- package/output/core/functions/expand/expand.js +376 -0
- package/output/core/functions/fresnelNumeric.d.ts +12 -0
- package/output/core/functions/fresnelNumeric.js +123 -0
- package/output/core/functions/numeric.d.ts +140 -0
- package/output/core/functions/numeric.js +790 -0
- package/output/core/functions/rationalNormalization.d.ts +11 -0
- package/output/core/functions/rationalNormalization.js +117 -0
- package/output/core/functions/setFunction.d.ts +19 -0
- package/output/core/functions/setFunction.js +75 -0
- package/output/core/functions/string.d.ts +26 -0
- package/output/core/functions/string.js +101 -0
- package/output/core/functions/subst.d.ts +90 -0
- package/output/core/functions/subst.js +498 -0
- package/output/core/functions/utils.d.ts +24 -0
- package/output/core/functions/utils.js +51 -0
- package/output/core/types.d.ts +48 -0
- package/output/core/types.js +2 -0
- package/output/index.d.ts +339 -0
- package/output/index.js +715 -0
- package/output/math/defint/defintDecimal.d.ts +37 -0
- package/output/math/defint/defintDecimal.js +320 -0
- package/output/math/defint/defintNative.d.ts +57 -0
- package/output/math/defint/defintNative.js +292 -0
- package/output/math/geometry.d.ts +8 -0
- package/output/math/geometry.js +32 -0
- package/output/math/math.d.ts +655 -0
- package/output/math/math.js +1811 -0
- package/output/math/trig.d.ts +518 -0
- package/output/math/trig.js +1444 -0
- package/output/math/trunc.d.ts +19 -0
- package/output/math/trunc.js +36 -0
- package/output/math/utils.d.ts +60 -0
- package/output/math/utils.js +180 -0
- package/output/solve/classes/DecimalMatrix.d.ts +17 -0
- package/output/solve/classes/DecimalMatrix.js +86 -0
- package/output/solve/classes/FunctionSolver.d.ts +135 -0
- package/output/solve/classes/FunctionSolver.js +433 -0
- package/output/solve/classes/MultivariateSolver.d.ts +84 -0
- package/output/solve/classes/MultivariateSolver.js +240 -0
- package/output/solve/classes/PolynomialSolver.d.ts +85 -0
- package/output/solve/classes/PolynomialSolver.js +292 -0
- package/output/solve/classes/SolutionSet.d.ts +153 -0
- package/output/solve/classes/SolutionSet.js +357 -0
- package/output/solve/classes/Solver.d.ts +17 -0
- package/output/solve/classes/Solver.js +132 -0
- package/output/solve/classes/SymbolicSolver.d.ts +74 -0
- package/output/solve/classes/SymbolicSolver.js +601 -0
- package/output/solve/linsolve.d.ts +51 -0
- package/output/solve/linsolve.js +225 -0
- package/output/solve/solve.d.ts +34 -0
- package/output/solve/solve.js +260 -0
- package/output/solve/solveSystem.d.ts +31 -0
- package/output/solve/solveSystem.js +290 -0
- package/output/solve/utils.d.ts +9 -0
- package/output/solve/utils.js +62 -0
- package/output/utils/array.d.ts +42 -0
- package/output/utils/array.js +98 -0
- package/output/utils/debug.d.ts +131 -0
- package/output/utils/debug.js +295 -0
- package/output/utils/decimal.d.ts +3 -0
- package/output/utils/decimal.js +16 -0
- package/output/utils/numeric.d.ts +14 -0
- package/output/utils/numeric.js +51 -0
- package/output/utils/object.d.ts +26 -0
- package/output/utils/object.js +56 -0
- package/package.json +213 -57
- package/.travis.yml +0 -3
- package/Algebra.js +0 -4568
- package/BREAKING_CHANGES.md +0 -5
- package/CODE_OF_CONDUCT.md +0 -46
- package/CONTRIBUTING.md +0 -14
- package/Calculus.js +0 -2675
- package/Extra.js +0 -622
- package/Solve.js +0 -1783
- package/all.js +0 -16
- package/all.min.js +0 -1
- package/gulpfile.js +0 -16
- package/index.html +0 -158
- package/license.txt +0 -19
- package/nerdamer.core.js +0 -12510
- package/spec/LaTeX.spec.js +0 -302
- package/spec/TeXConvert.spec.js +0 -8
- package/spec/algebra.spec.js +0 -287
- package/spec/basic_parser.spec.js +0 -134
- package/spec/build.spec.js +0 -131
- package/spec/calculus.spec.js +0 -183
- package/spec/core.spec.js +0 -2970
- package/spec/extra.spec.js +0 -54
- package/spec/solve.spec.js +0 -126
- package/spec/support/jasmine.json +0 -11
- package/spec/support/utils.js +0 -42
- package/spec/text.spec.js +0 -132
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import { Expression } from '../expression/Expression';
|
|
3
|
+
import { RATIONAL } from '../parser/constants';
|
|
4
|
+
import type { OptionsObject } from '../parser/types';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an exact rational value as a `bigint` numerator and denominator.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Core rational arithmetic is exact: decimal and scientific-notation input is converted to
|
|
10
|
+
* the exact fraction represented by the input text rather than stored as a floating-point
|
|
11
|
+
* approximation. The notable exception is non-integer {@link Rational.pow}, which uses
|
|
12
|
+
* `decimal.js` numerical exponentiation. The {@link Rational.asDecimal} flag records
|
|
13
|
+
* presentation intent only; it does not change the underlying rational representation.
|
|
14
|
+
*
|
|
15
|
+
* Values produced by {@link Rational.create} and the arithmetic methods are normally reduced
|
|
16
|
+
* and use a positive denominator. The public constructor is lower level: it stores its two
|
|
17
|
+
* `bigint` arguments exactly as supplied and does not reduce the fraction, normalize the
|
|
18
|
+
* denominator sign, or reject a zero denominator. Sign, comparison, and integer helpers assume
|
|
19
|
+
* the normal representation, so callers constructing values directly are responsible for
|
|
20
|
+
* preserving that representation.
|
|
21
|
+
*
|
|
22
|
+
* `Rational` instances are mutable because their representation fields are public and
|
|
23
|
+
* {@link Rational.updateValue} updates the instance in place. The ordinary arithmetic methods
|
|
24
|
+
* return new values and do not mutate their operands.
|
|
25
|
+
*/
|
|
26
|
+
export declare class Rational {
|
|
27
|
+
/**
|
|
28
|
+
* Finite-precision rational approximation of Euler's number at the current configured precision.
|
|
29
|
+
*
|
|
30
|
+
* Recomputed when {@link Rational.set} changes the precision.
|
|
31
|
+
*/
|
|
32
|
+
static E: Rational;
|
|
33
|
+
/**
|
|
34
|
+
* Finite-precision rational approximation of pi at the current configured precision.
|
|
35
|
+
*
|
|
36
|
+
* Recomputed when {@link Rational.set} changes the precision.
|
|
37
|
+
*/
|
|
38
|
+
static PI: Rational;
|
|
39
|
+
/**
|
|
40
|
+
* Precision setting shared with `decimal.js` and used as the default digit count by
|
|
41
|
+
* {@link Rational.toDecimalString}. Change it through {@link Rational.set}.
|
|
42
|
+
*/
|
|
43
|
+
private static precision;
|
|
44
|
+
/**
|
|
45
|
+
* Whether text output should preserve decimal presentation by default.
|
|
46
|
+
*
|
|
47
|
+
* This flag does not change the exact numerator/denominator representation. Most rational
|
|
48
|
+
* arithmetic propagates decimal intent when either operand has it set.
|
|
49
|
+
*/
|
|
50
|
+
asDecimal: boolean;
|
|
51
|
+
/** Marker used by Nerdamer's runtime type guards. */
|
|
52
|
+
dataType: typeof RATIONAL;
|
|
53
|
+
/** Denominator of the exact rational representation. */
|
|
54
|
+
denominator: bigint;
|
|
55
|
+
/** Numerator of the exact rational representation. */
|
|
56
|
+
numerator: bigint;
|
|
57
|
+
/**
|
|
58
|
+
* The supplied textual value.
|
|
59
|
+
*
|
|
60
|
+
* Numeric behavior is defined by {@link Rational.numerator} and
|
|
61
|
+
* {@link Rational.denominator}; callers should not treat this field as an independent
|
|
62
|
+
* authoritative numeric representation.
|
|
63
|
+
*/
|
|
64
|
+
value: string;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a rational from raw numerator and denominator components.
|
|
67
|
+
*
|
|
68
|
+
* @remarks
|
|
69
|
+
* This constructor performs no normalization or validation. Prefer
|
|
70
|
+
* {@link Rational.create} for user input and for values that must use Nerdamer's normal
|
|
71
|
+
* reduced-fraction representation.
|
|
72
|
+
*
|
|
73
|
+
* @param a - Numerator to store.
|
|
74
|
+
* @param b - Denominator to store.
|
|
75
|
+
*/
|
|
76
|
+
constructor(a: bigint, b: bigint);
|
|
77
|
+
/**
|
|
78
|
+
* Tests whether every supplied rational is strictly negative.
|
|
79
|
+
*
|
|
80
|
+
* @param args - Rational values to test.
|
|
81
|
+
* @returns `true` when each value has sign `-1`.
|
|
82
|
+
*/
|
|
83
|
+
static allNegative(...args: Rational[]): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Creates a normalized rational from an integer, fraction, decimal, or scientific-notation value.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* Fraction strings are reduced and a negative denominator is moved to the numerator. Decimal
|
|
89
|
+
* and scientific-notation strings are converted to the exact rational represented by their
|
|
90
|
+
* finite decimal text. Those forms also set {@link Rational.asDecimal}, so later text output
|
|
91
|
+
* normally remains decimal even though the stored arithmetic stays exact.
|
|
92
|
+
*
|
|
93
|
+
* @param value - Integer `bigint` or numeric string to convert.
|
|
94
|
+
* @returns A new normalized `Rational`.
|
|
95
|
+
*
|
|
96
|
+
* @throws {@link DivisionByZeroError}
|
|
97
|
+
* Thrown when a fraction string has a zero denominator.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* Rational.create('2/4').text(); // "1/2"
|
|
102
|
+
* Rational.create('0.125').text(); // "0.125"
|
|
103
|
+
* Rational.create('4e1').text(); // "40.0"
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
static create(value: string | bigint): Rational;
|
|
107
|
+
/**
|
|
108
|
+
* Computes the rational greatest common divisor across the supplied values.
|
|
109
|
+
*
|
|
110
|
+
* @remarks
|
|
111
|
+
* The operation is folded pairwise and preserves decimal presentation intent when it is
|
|
112
|
+
* present on an operand.
|
|
113
|
+
*
|
|
114
|
+
* @param args - Rational values whose common divisor should be computed.
|
|
115
|
+
* @returns The pairwise rational GCD.
|
|
116
|
+
*/
|
|
117
|
+
static GCD(...args: Rational[]): Rational;
|
|
118
|
+
/**
|
|
119
|
+
* Returns the currently configured rational/Decimal precision setting.
|
|
120
|
+
*
|
|
121
|
+
* @returns The configured precision value.
|
|
122
|
+
*/
|
|
123
|
+
static getPrecision(): number;
|
|
124
|
+
/**
|
|
125
|
+
* Returns a value unchanged for compatibility with generic numeric hooks.
|
|
126
|
+
*
|
|
127
|
+
* @param value - Value to pass through.
|
|
128
|
+
* @returns The same value reference or primitive supplied by the caller.
|
|
129
|
+
*/
|
|
130
|
+
static hook(value: string | Rational | bigint): string | bigint | Rational;
|
|
131
|
+
/**
|
|
132
|
+
* Tests whether a value carries Nerdamer's rational runtime type marker.
|
|
133
|
+
*
|
|
134
|
+
* @remarks
|
|
135
|
+
* This is a marker-based guard rather than an `instanceof` check, which allows compatible
|
|
136
|
+
* Nerdamer rational objects to be recognized where constructor identity is not the useful
|
|
137
|
+
* distinction.
|
|
138
|
+
*
|
|
139
|
+
* @param value - Value to inspect.
|
|
140
|
+
* @returns `true` when `value.dataType` is Nerdamer's rational marker.
|
|
141
|
+
*/
|
|
142
|
+
static isRational(value: unknown): value is Rational;
|
|
143
|
+
/**
|
|
144
|
+
* Computes the rational least common multiple across the supplied values.
|
|
145
|
+
*
|
|
146
|
+
* @remarks
|
|
147
|
+
* The operation is folded pairwise and preserves decimal presentation intent when it is
|
|
148
|
+
* present on an operand.
|
|
149
|
+
*
|
|
150
|
+
* @param args - Rational values whose common multiple should be computed.
|
|
151
|
+
* @returns The pairwise rational LCM.
|
|
152
|
+
*/
|
|
153
|
+
static LCM(...args: Rational[]): Rational;
|
|
154
|
+
/**
|
|
155
|
+
* Copies a rational's representation and presentation metadata.
|
|
156
|
+
*
|
|
157
|
+
* @param x - Rational to copy.
|
|
158
|
+
* @returns A distinct `Rational` with the same numerator, denominator, `value`, and
|
|
159
|
+
* decimal-presentation flag.
|
|
160
|
+
*/
|
|
161
|
+
static makeCopy(x: Rational): Rational;
|
|
162
|
+
/**
|
|
163
|
+
* Updates shared numeric settings used by rational decimal conversion.
|
|
164
|
+
*
|
|
165
|
+
* @remarks
|
|
166
|
+
* Currently only `precision` is acted upon. Setting it updates the global `decimal.js`
|
|
167
|
+
* precision, records the value used by {@link Rational.toDecimalString}, and recomputes
|
|
168
|
+
* {@link Rational.PI} and {@link Rational.E} at the new precision.
|
|
169
|
+
*
|
|
170
|
+
* @param values - Settings object; `precision` is the supported numeric setting.
|
|
171
|
+
*/
|
|
172
|
+
static set(values: {
|
|
173
|
+
[key: string]: number | boolean;
|
|
174
|
+
}): void;
|
|
175
|
+
/**
|
|
176
|
+
* Converts a string to a rational or normalizes rational ownership for a caller.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Strings always produce a new value through {@link Rational.create}. An existing `Rational`
|
|
180
|
+
* is returned by identity unless `ensureCopy` is `true`.
|
|
181
|
+
*
|
|
182
|
+
* @param x - Numeric string or rational value.
|
|
183
|
+
* @param ensureCopy - Guarantee a distinct object when `x` is already a `Rational`.
|
|
184
|
+
* @returns The converted rational, a copy, or the original rational according to `ensureCopy`.
|
|
185
|
+
*/
|
|
186
|
+
static toRational(x: string | Rational, ensureCopy?: boolean): Rational;
|
|
187
|
+
/**
|
|
188
|
+
* Returns the absolute value without modifying this rational.
|
|
189
|
+
*
|
|
190
|
+
* @returns A copied rational whose numerator is nonnegative.
|
|
191
|
+
*/
|
|
192
|
+
abs(): Rational;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a distinct copy of this rational.
|
|
195
|
+
*
|
|
196
|
+
* @returns A new object with the same numeric representation and presentation metadata.
|
|
197
|
+
*/
|
|
198
|
+
copy(): Rational;
|
|
199
|
+
/**
|
|
200
|
+
* Divides using Nerdamer's rational or expression arithmetic overloads.
|
|
201
|
+
*
|
|
202
|
+
* @remarks
|
|
203
|
+
* `Rational` and string operands compute exact rational division and return a new `Rational`.
|
|
204
|
+
* Expression operands promote this rational to an {@link Expression} and preserve operand
|
|
205
|
+
* direction, returning `this / expression`.
|
|
206
|
+
*
|
|
207
|
+
* @param num - Value participating in the division.
|
|
208
|
+
* @returns A rational result for rational/string input, or an `Expression` for expression input.
|
|
209
|
+
* @throws {@link DivisionByZeroError}
|
|
210
|
+
* Thrown when exact rational division requires inversion of zero.
|
|
211
|
+
*/
|
|
212
|
+
div(num: Expression): Expression;
|
|
213
|
+
div(num: Rational | string): Rational;
|
|
214
|
+
/**
|
|
215
|
+
* Compares this rational with another value for mathematical equality.
|
|
216
|
+
*
|
|
217
|
+
* @remarks
|
|
218
|
+
* Rational/string comparisons are exact and use cross multiplication, so decimal-presentation
|
|
219
|
+
* metadata does not affect equality. Expression input delegates to Nerdamer's symbolic
|
|
220
|
+
* comparison semantics.
|
|
221
|
+
*
|
|
222
|
+
* @param num - Value to compare with this rational.
|
|
223
|
+
* @returns `true` when the two values compare equal.
|
|
224
|
+
*/
|
|
225
|
+
eq(num: Expression): boolean;
|
|
226
|
+
eq(num: Rational | string): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Tests whether the stored denominator is even.
|
|
229
|
+
*
|
|
230
|
+
* @returns `true` when {@link Rational.denominator} is divisible by two.
|
|
231
|
+
*/
|
|
232
|
+
evenDenominator(): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Tests whether the stored numerator is even.
|
|
235
|
+
*
|
|
236
|
+
* @returns `true` when {@link Rational.numerator} is divisible by two.
|
|
237
|
+
*/
|
|
238
|
+
evenNumerator(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* Computes the rational greatest common divisor with another value.
|
|
241
|
+
*
|
|
242
|
+
* @param num - Rational or numeric string to combine with this value.
|
|
243
|
+
* @returns A new reduced rational GCD. Decimal presentation is preserved when either operand
|
|
244
|
+
* was marked for decimal output.
|
|
245
|
+
*/
|
|
246
|
+
GCD(num: Rational | string): Rational;
|
|
247
|
+
/**
|
|
248
|
+
* Tests whether this rational is greater than another value.
|
|
249
|
+
*
|
|
250
|
+
* @remarks
|
|
251
|
+
* Rational/string comparisons are exact. Expression input delegates to Nerdamer's symbolic
|
|
252
|
+
* ordering rules, including their restrictions on unordered complex values.
|
|
253
|
+
*
|
|
254
|
+
* @param num - Value to compare against.
|
|
255
|
+
* @returns `true` when this rational is greater than `num`.
|
|
256
|
+
*/
|
|
257
|
+
gt(num: Expression): boolean;
|
|
258
|
+
gt(num: Rational | string): boolean;
|
|
259
|
+
/**
|
|
260
|
+
* Tests whether this rational is greater than or equal to another rational value.
|
|
261
|
+
*
|
|
262
|
+
* @param num - Rational or numeric string to compare against.
|
|
263
|
+
* @returns `true` when this rational is greater than or equal to `num`.
|
|
264
|
+
*/
|
|
265
|
+
gte(num: Rational | string): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* Returns the multiplicative inverse of this rational.
|
|
268
|
+
*
|
|
269
|
+
* @remarks
|
|
270
|
+
* The original object is not modified. For normally constructed rationals, the returned
|
|
271
|
+
* denominator remains positive and the sign is carried by the numerator.
|
|
272
|
+
*
|
|
273
|
+
* @returns A new rational representing `1 / this`.
|
|
274
|
+
* @throws {@link DivisionByZeroError}
|
|
275
|
+
* Thrown when this rational is exactly zero.
|
|
276
|
+
*/
|
|
277
|
+
invert(): Rational;
|
|
278
|
+
/**
|
|
279
|
+
* Tests whether this value is an even integer.
|
|
280
|
+
*
|
|
281
|
+
* @returns `true` only when the denominator is one and the numerator is even.
|
|
282
|
+
*/
|
|
283
|
+
isEven(): boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Tests whether this rational is stored in integer form.
|
|
286
|
+
*
|
|
287
|
+
* @remarks
|
|
288
|
+
* This checks only whether the denominator is exactly `1n`. Values built with the raw
|
|
289
|
+
* constructor must therefore be reduced first if equivalent forms such as `8/4` should be
|
|
290
|
+
* recognized as integers.
|
|
291
|
+
*
|
|
292
|
+
* @returns `true` when the stored denominator is one.
|
|
293
|
+
*/
|
|
294
|
+
isInteger(): boolean;
|
|
295
|
+
/**
|
|
296
|
+
* Tests whether this rational is exactly `-1` in normalized integer form.
|
|
297
|
+
*
|
|
298
|
+
* @returns `true` for numerator `-1n` and denominator `1n`.
|
|
299
|
+
*/
|
|
300
|
+
isMinusOne(): boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Tests whether the stored numerator is negative.
|
|
303
|
+
*
|
|
304
|
+
* @remarks
|
|
305
|
+
* Nerdamer's normal rational representation keeps the denominator positive, so the numerator
|
|
306
|
+
* carries the sign. Raw constructor values with a negative denominator do not follow that
|
|
307
|
+
* representation.
|
|
308
|
+
*
|
|
309
|
+
* @returns `true` when the numerator is negative.
|
|
310
|
+
*/
|
|
311
|
+
isNegative(): boolean;
|
|
312
|
+
/**
|
|
313
|
+
* Tests whether this rational is exactly `1` in normalized integer form.
|
|
314
|
+
*
|
|
315
|
+
* @returns `true` for numerator `1n` and denominator `1n`.
|
|
316
|
+
*/
|
|
317
|
+
isOne(): boolean;
|
|
318
|
+
/**
|
|
319
|
+
* Tests whether this rational is exactly zero.
|
|
320
|
+
*
|
|
321
|
+
* @returns `true` when the numerator is zero.
|
|
322
|
+
*/
|
|
323
|
+
isZero(): boolean;
|
|
324
|
+
/**
|
|
325
|
+
* Computes the rational least common multiple with another value.
|
|
326
|
+
*
|
|
327
|
+
* @param num - Rational or numeric string to combine with this value.
|
|
328
|
+
* @returns A new reduced, nonnegative rational LCM. Zero combined with any rational returns
|
|
329
|
+
* zero. Decimal presentation is preserved when either operand was marked for decimal output.
|
|
330
|
+
*/
|
|
331
|
+
LCM(num: Rational | string): Rational;
|
|
332
|
+
/**
|
|
333
|
+
* Tests whether this rational is less than another rational value.
|
|
334
|
+
*
|
|
335
|
+
* @param num - Rational or numeric string to compare against.
|
|
336
|
+
* @returns `true` when this rational is less than `num`.
|
|
337
|
+
*/
|
|
338
|
+
lt(num: Rational | string): boolean;
|
|
339
|
+
/**
|
|
340
|
+
* Tests whether this rational is less than or equal to another rational value.
|
|
341
|
+
*
|
|
342
|
+
* @param num - Rational or numeric string to compare against.
|
|
343
|
+
* @returns `true` when this rational is less than or equal to `num`.
|
|
344
|
+
*/
|
|
345
|
+
lte(num: Rational | string): boolean;
|
|
346
|
+
/**
|
|
347
|
+
* Subtracts another rational or expression from this value.
|
|
348
|
+
*
|
|
349
|
+
* @remarks
|
|
350
|
+
* Rational/string input is handled with exact rational arithmetic. Expression input is
|
|
351
|
+
* promoted to Nerdamer's symbolic arithmetic. The original operands are not mutated.
|
|
352
|
+
*
|
|
353
|
+
* @param num - Value to subtract.
|
|
354
|
+
* @returns A new `Rational` for rational/string input, or an `Expression` for expression input.
|
|
355
|
+
*/
|
|
356
|
+
minus(num: Expression): Expression;
|
|
357
|
+
minus(num: Rational | string): Rational;
|
|
358
|
+
/**
|
|
359
|
+
* Computes the exact rational modulo with another value.
|
|
360
|
+
*
|
|
361
|
+
* @remarks
|
|
362
|
+
* The operands are converted to a common denominator, Nerdamer's integer modulo operation is
|
|
363
|
+
* applied to the corresponding numerators, and the resulting fraction is reduced. Decimal
|
|
364
|
+
* presentation is preserved when either operand was marked for decimal output.
|
|
365
|
+
*
|
|
366
|
+
* @param num - Nonzero rational or numeric string used as the modulus.
|
|
367
|
+
* @returns The reduced rational remainder.
|
|
368
|
+
* @throws A native `RangeError` when `num` is zero.
|
|
369
|
+
*/
|
|
370
|
+
mod(num: Rational | string): Rational;
|
|
371
|
+
/**
|
|
372
|
+
* Returns the additive inverse of this rational.
|
|
373
|
+
*
|
|
374
|
+
* @returns A new rational with the numerator sign reversed.
|
|
375
|
+
*/
|
|
376
|
+
neg(): Rational;
|
|
377
|
+
/**
|
|
378
|
+
* Adds another rational or expression to this value.
|
|
379
|
+
*
|
|
380
|
+
* @remarks
|
|
381
|
+
* Rational/string input is added exactly and reduced. If either rational operand carries
|
|
382
|
+
* decimal presentation intent, the rational result carries it as well. Expression input is
|
|
383
|
+
* promoted to Nerdamer's symbolic arithmetic.
|
|
384
|
+
*
|
|
385
|
+
* @param num - Value to add.
|
|
386
|
+
* @returns A new `Rational` for rational/string input, or an `Expression` for expression input.
|
|
387
|
+
*/
|
|
388
|
+
plus(num: Expression): Expression;
|
|
389
|
+
plus(num: Rational | string): Rational;
|
|
390
|
+
/**
|
|
391
|
+
* Raises this rational to a rational or symbolic power.
|
|
392
|
+
*
|
|
393
|
+
* @remarks
|
|
394
|
+
* Expression exponents use Nerdamer's general symbolic power logic. Integer rational
|
|
395
|
+
* exponents use exact `bigint` exponentiation, with negative exponents handled by first
|
|
396
|
+
* inverting the base. Non-integer rational exponents are evaluated through `decimal.js` and
|
|
397
|
+
* converted back to a `Rational`, so that overload is a real numerical approximation rather
|
|
398
|
+
* than symbolic radical or principal-complex evaluation. Decimal presentation from a numerical
|
|
399
|
+
* result is retained, while an exact integer result stays exact unless the base already carried
|
|
400
|
+
* decimal presentation intent.
|
|
401
|
+
*
|
|
402
|
+
* @param num - Exponent to apply.
|
|
403
|
+
* @returns A rational result for rational/string input, or an `Expression` for expression input.
|
|
404
|
+
* @throws {@link ZeroToZeroPowerError}
|
|
405
|
+
* Thrown for the indeterminate form `0^0`.
|
|
406
|
+
* @throws {@link DivisionByZeroError}
|
|
407
|
+
* Thrown when zero is raised to a negative integer power.
|
|
408
|
+
*/
|
|
409
|
+
pow(num: Expression): Expression;
|
|
410
|
+
pow(num: Rational | string): Rational;
|
|
411
|
+
/**
|
|
412
|
+
* Returns the sign carried by the numerator.
|
|
413
|
+
*
|
|
414
|
+
* @returns `-1` for a negative numerator, `0` for zero, or `1` for a positive numerator.
|
|
415
|
+
*/
|
|
416
|
+
sign(): number;
|
|
417
|
+
/**
|
|
418
|
+
* Formats this rational as fraction, integer, or decimal text.
|
|
419
|
+
*
|
|
420
|
+
* @remarks
|
|
421
|
+
* Decimal formatting is selected when {@link Rational.asDecimal} is set or when
|
|
422
|
+
* `options.decimal` is truthy. Non-integer decimal output uses `decimal.js`; an optional
|
|
423
|
+
* `options.precision` temporarily controls its significant-digit precision for this conversion.
|
|
424
|
+
* Integer decimal output includes a `.0` suffix. Without decimal formatting, non-integer
|
|
425
|
+
* fractions are emitted from the stored numerator and denominator, and integers as plain text.
|
|
426
|
+
*
|
|
427
|
+
* @param options - Formatting options. `decimal` forces decimal output and `precision` controls
|
|
428
|
+
* decimal conversion precision when applicable.
|
|
429
|
+
* @returns The formatted numeric text.
|
|
430
|
+
*/
|
|
431
|
+
text(options?: OptionsObject): string;
|
|
432
|
+
/**
|
|
433
|
+
* Multiplies this rational by another rational or expression.
|
|
434
|
+
*
|
|
435
|
+
* @remarks
|
|
436
|
+
* Rational/string multiplication is exact and reduced. If either rational operand carries
|
|
437
|
+
* decimal presentation intent, the rational result carries it as well. Expression input is
|
|
438
|
+
* promoted to Nerdamer's symbolic arithmetic.
|
|
439
|
+
*
|
|
440
|
+
* @param num - Value to multiply by.
|
|
441
|
+
* @returns A new `Rational` for rational/string input, or an `Expression` for expression input.
|
|
442
|
+
*/
|
|
443
|
+
times(num: Expression): Expression;
|
|
444
|
+
times(num: Rational | string): Rational;
|
|
445
|
+
/**
|
|
446
|
+
* Converts the exact fraction to a `decimal.js` value at the current global Decimal precision.
|
|
447
|
+
*
|
|
448
|
+
* Integer rationals avoid an unnecessary Decimal division.
|
|
449
|
+
*
|
|
450
|
+
* @returns A new Decimal representing `numerator / denominator`.
|
|
451
|
+
*/
|
|
452
|
+
toDecimal(): Decimal;
|
|
453
|
+
/**
|
|
454
|
+
* Converts the exact fraction to decimal text using integer arithmetic.
|
|
455
|
+
*
|
|
456
|
+
* @remarks
|
|
457
|
+
* `precision` is the maximum number of digits generated after the decimal point. The
|
|
458
|
+
* conversion truncates at that position rather than rounding, then removes trailing zeros
|
|
459
|
+
* and a trailing decimal point. When omitted, the configured Rational precision is used.
|
|
460
|
+
*
|
|
461
|
+
* This method does not depend on {@link Rational.asDecimal}; it always requests decimal text.
|
|
462
|
+
*
|
|
463
|
+
* @param precision - Number of fractional digits to generate.
|
|
464
|
+
* @returns Truncated decimal text with unnecessary trailing zeros removed.
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```ts
|
|
468
|
+
* Rational.create('1/3').toDecimalString(5); // "0.33333"
|
|
469
|
+
* Rational.create('7/4').toDecimalString(5); // "1.75"
|
|
470
|
+
* ```
|
|
471
|
+
*/
|
|
472
|
+
toDecimalString(precision?: number): string;
|
|
473
|
+
/**
|
|
474
|
+
* Returns the same formatted representation as {@link Rational.text}.
|
|
475
|
+
*
|
|
476
|
+
* @param options - Formatting options forwarded to `text`.
|
|
477
|
+
* @returns The formatted rational string.
|
|
478
|
+
*/
|
|
479
|
+
toString(options?: OptionsObject): string;
|
|
480
|
+
/**
|
|
481
|
+
* Refreshes {@link Rational.value} from the current numerator and denominator.
|
|
482
|
+
*
|
|
483
|
+
* @remarks
|
|
484
|
+
* This is one of the few mutating methods on `Rational`; it updates this object and returns
|
|
485
|
+
* the same reference.
|
|
486
|
+
*
|
|
487
|
+
* @returns This rational instance.
|
|
488
|
+
*/
|
|
489
|
+
updateValue(): this;
|
|
490
|
+
/**
|
|
491
|
+
* Converts this rational to a native JavaScript number.
|
|
492
|
+
*
|
|
493
|
+
* @remarks
|
|
494
|
+
* This conversion is approximate and subject to the range and precision limits of
|
|
495
|
+
* JavaScript `number`. Numerator and denominator values that are both safe integers use
|
|
496
|
+
* native division directly; larger values retain the Decimal-backed fallback so finite ratios
|
|
497
|
+
* are not lost merely because an individual component exceeds the native numeric range.
|
|
498
|
+
* Use the rational representation or {@link Rational.toDecimal} when native-number limits
|
|
499
|
+
* are unacceptable.
|
|
500
|
+
*
|
|
501
|
+
* @returns The approximate native numeric value.
|
|
502
|
+
*/
|
|
503
|
+
valueOf(): number;
|
|
504
|
+
}
|