@danielsimonjr/mathts-core 0.8.0 → 0.10.0

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.
@@ -2410,23 +2410,28 @@ var BigNumber = class _BigNumber {
2410
2410
  // ============================================================
2411
2411
  // Comparison Methods
2412
2412
  // ============================================================
2413
+ // All comparisons coerce their argument (number/string → BigNumber) exactly like the arithmetic
2414
+ // methods, so `bignumber(8).lessThanOrEqual(3)` behaves like `.add(3)` does. Without the
2415
+ // coercion the raw number reached the static comparator, which read `undefined._sign` and
2416
+ // returned garbage — silently breaking every factory-layer consumer that compares against a
2417
+ // number literal (isPrime, quantiles, …).
2413
2418
  equals(other) {
2414
- return _BigNumber.compare(this, other) === 0;
2419
+ return _BigNumber.compare(this, this.ensureBigNumber(other)) === 0;
2415
2420
  }
2416
2421
  lessThan(other) {
2417
- return _BigNumber.compare(this, other) < 0;
2422
+ return _BigNumber.compare(this, this.ensureBigNumber(other)) < 0;
2418
2423
  }
2419
2424
  lessThanOrEqual(other) {
2420
- return _BigNumber.compare(this, other) <= 0;
2425
+ return _BigNumber.compare(this, this.ensureBigNumber(other)) <= 0;
2421
2426
  }
2422
2427
  greaterThan(other) {
2423
- return _BigNumber.compare(this, other) > 0;
2428
+ return _BigNumber.compare(this, this.ensureBigNumber(other)) > 0;
2424
2429
  }
2425
2430
  greaterThanOrEqual(other) {
2426
- return _BigNumber.compare(this, other) >= 0;
2431
+ return _BigNumber.compare(this, this.ensureBigNumber(other)) >= 0;
2427
2432
  }
2428
2433
  compareTo(other) {
2429
- return _BigNumber.compare(this, other);
2434
+ return _BigNumber.compare(this, this.ensureBigNumber(other));
2430
2435
  }
2431
2436
  compare(other) {
2432
2437
  return this.compareTo(other);
@@ -2437,7 +2442,7 @@ var BigNumber = class _BigNumber {
2437
2442
  * Named `gt` for Decimal.js / mathjs formatter compatibility.
2438
2443
  */
2439
2444
  gt(other) {
2440
- return this.greaterThan(this.ensureBigNumber(other));
2445
+ return this.greaterThan(other);
2441
2446
  }
2442
2447
  // ============================================================
2443
2448
  // Rounding Methods
package/dist/index.d.ts CHANGED
@@ -1720,13 +1720,13 @@ declare class BigNumber implements MathTSValue {
1720
1720
  * Square root
1721
1721
  */
1722
1722
  sqrt(): BigNumber;
1723
- equals(other: BigNumber): boolean;
1724
- lessThan(other: BigNumber): boolean;
1725
- lessThanOrEqual(other: BigNumber): boolean;
1726
- greaterThan(other: BigNumber): boolean;
1727
- greaterThanOrEqual(other: BigNumber): boolean;
1728
- compareTo(other: BigNumber): number;
1729
- compare(other: BigNumber): number;
1723
+ equals(other: BigNumber | number | string): boolean;
1724
+ lessThan(other: BigNumber | number | string): boolean;
1725
+ lessThanOrEqual(other: BigNumber | number | string): boolean;
1726
+ greaterThan(other: BigNumber | number | string): boolean;
1727
+ greaterThanOrEqual(other: BigNumber | number | string): boolean;
1728
+ compareTo(other: BigNumber | number | string): number;
1729
+ compare(other: BigNumber | number | string): number;
1730
1730
  /**
1731
1731
  * Returns true iff this > other.
1732
1732
  * Accepts the same argument types as `add`/`multiply` (BigNumber, number, or string).
@@ -2538,6 +2538,23 @@ declare function pairwiseDot(a: ArrayLike<number>, b: ArrayLike<number>, start?:
2538
2538
  * The two ranges are assumed the same length; callers guard that.
2539
2539
  */
2540
2540
  declare function scaledDistance(a: ArrayLike<number>, b: ArrayLike<number>): number;
2541
+ /**
2542
+ * Sum of squared deviations from the mean, `Σ(xᵢ − x̄)²` — the **corrected two-pass** form, the
2543
+ * numerator of a numerically stable variance.
2544
+ *
2545
+ * Variance is where large means bite: the deviations `xᵢ − x̄` can be O(1) while the values sit on
2546
+ * a huge pedestal, so any error in `x̄` rides straight into every deviation. Two things fix it:
2547
+ * 1. compute the mean with {@link pairwiseSum}, not a naive running total; and
2548
+ * 2. subtract the residual mean-bias term `(Σd)²/n` — `Σd` is zero in exact arithmetic but not in
2549
+ * floating point, and that leftover is exactly the systematic error a plain `Σd²` carries.
2550
+ *
2551
+ * Measured on 1e9-pedestal data: the plain naive two-pass (what shipped) lands ~1e-7 relative error;
2552
+ * this lands ~1e-16 — better than `np.var`, which uses the uncorrected two-pass (~1e-13).
2553
+ *
2554
+ * Divide the result by `n` (uncorrected), `n − 1` (unbiased/sample), or `n + 1` (biased) for the
2555
+ * corresponding variance. Returns 0 for fewer than two elements.
2556
+ */
2557
+ declare function sumSquaredDeviations(xs: ArrayLike<number>): number;
2541
2558
  /**
2542
2559
  * Cumulative sum with **Neumaier compensation** — each prefix total is written to `out[i]` carrying
2543
2560
  * the low-order bits a naive running sum throws away.
@@ -2562,4 +2579,4 @@ declare function neumaierCumsum(xs: ArrayLike<number>, out: {
2562
2579
 
2563
2580
  declare const VERSION = "0.1.0";
2564
2581
 
2565
- export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, Range, type RangeForEachCallback, type RangeFormatOptions, type RangeJSON, type RangeMapCallback, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, registerNativeTypes, registry, round, scaledDistance, subtractScalar };
2582
+ export { ALL_UNITS, BASE_UNITS, BEST_PREFIXES, BIGNUMBER_E, BIGNUMBER_LN10, BIGNUMBER_LN2, BIGNUMBER_NEG_ONE, BIGNUMBER_ONE, BIGNUMBER_PI, BIGNUMBER_TEN, BIGNUMBER_ZERO, type BackendType, BigNumber, type BigNumberConfig, COMPLEX_NEG_ONE, COMPLEX_ONE, COMPLEX_ZERO, Complex, type ConversionDef, DEFAULT_CONFIG, DERIVED_UNITS, DIMENSIONLESS, DUAL_UNARY_RULES, DimensionMismatchError, type Dimensions, Dual, type DualUnaryRule, type DualUnaryRuleName, E, FRACTION_HALF, FRACTION_NEG_ONE, FRACTION_ONE, FRACTION_QUARTER, FRACTION_THIRD, FRACTION_ZERO, type FactoryDependencies, type FactoryFunction, type FactoryImport, Fraction, FunctionRegistry, I, type IBigNumber, type IComplex, type IFraction, type IMatrix, LN10, LN2, LOG10E, LOG2E, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericScalar, type NumericType, PHI, PI, Range, type RangeForEachCallback, type RangeFormatOptions, type RangeJSON, type RangeMapCallback, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, type UnitDef, UnitParseError, VERSION, abs, addScalar, createFactory, createMathTSTyped, createRangeClass, createTypedFunction, dim, divideScalar, equal, fix, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isNumeric, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, math, mathTyped, multiplyScalar, neumaierCumsum, neumaierSum, norm2, number, pairwiseDot, pairwiseSum, pow, registerNativeTypes, registry, round, scaledDistance, subtractScalar, sumSquaredDeviations };
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  round,
45
45
  sign,
46
46
  subtractScalar
47
- } from "./chunk-AMOHH5MP.js";
47
+ } from "./chunk-2WW76EEF.js";
48
48
 
49
49
  // src/types/matrix/Range.ts
50
50
  var name = "Range";
@@ -1297,6 +1297,17 @@ function scaledDistance(a, b) {
1297
1297
  }
1298
1298
  return scale === 0 ? 0 : scale * Math.sqrt(ssq);
1299
1299
  }
1300
+ function sumSquaredDeviations(xs) {
1301
+ const n = xs.length;
1302
+ if (n < 2) return 0;
1303
+ const mean = pairwiseSum(xs) / n;
1304
+ const d = new Float64Array(n);
1305
+ for (let i = 0; i < n; i++) d[i] = xs[i] - mean;
1306
+ const sumD = pairwiseSum(d);
1307
+ const sumDD = pairwiseDot(d, d);
1308
+ const corrected = sumDD - sumD * sumD / n;
1309
+ return corrected < 0 ? 0 : corrected;
1310
+ }
1300
1311
  function neumaierCumsum(xs, out) {
1301
1312
  let sum = 0;
1302
1313
  let c = 0;
@@ -1411,5 +1422,6 @@ export {
1411
1422
  round,
1412
1423
  scaledDistance,
1413
1424
  subtractScalar,
1425
+ sumSquaredDeviations,
1414
1426
  typed
1415
1427
  };
package/dist/internal.js CHANGED
@@ -69,7 +69,7 @@ import {
69
69
  typeOf,
70
70
  unitDependencies,
71
71
  warnOnce
72
- } from "./chunk-AMOHH5MP.js";
72
+ } from "./chunk-2WW76EEF.js";
73
73
  export {
74
74
  Unit as CoreUnit,
75
75
  acosh,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-core",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Core types, utilities, and configuration for MathTS",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",