@danielsimonjr/mathts-core 0.2.0 → 0.3.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/dist/index.d.ts CHANGED
@@ -464,6 +464,36 @@ declare class Dual {
464
464
  /** Type guard for {@link Dual}. */
465
465
  declare function isDual(x: unknown): x is Dual;
466
466
 
467
+ /**
468
+ * Named mathematical constants (plain `number`).
469
+ *
470
+ * These mirror the constants documented in `docs/reference/constants.md` and the
471
+ * familiar `Math.*` values, exported as first-class named bindings so callers can
472
+ * `import { PI, E, TAU } from '@danielsimonjr/mathts-core'`. The imaginary unit
473
+ * `I` and the type-specific constants (`COMPLEX_*`, `BIGNUMBER_*`, `FRACTION_*`)
474
+ * live with their respective types.
475
+ */
476
+ /** Ratio of a circle's circumference to its diameter. */
477
+ declare const PI: number;
478
+ /** Euler's number, the base of the natural logarithm. */
479
+ declare const E: number;
480
+ /** Full-circle constant, `2·PI`. */
481
+ declare const TAU: number;
482
+ /** Golden ratio, `(1 + √5) / 2`. */
483
+ declare const PHI: number;
484
+ /** Square root of 2. */
485
+ declare const SQRT2: number;
486
+ /** Square root of one-half. */
487
+ declare const SQRT1_2: number;
488
+ /** Natural logarithm of 2. */
489
+ declare const LN2: number;
490
+ /** Natural logarithm of 10. */
491
+ declare const LN10: number;
492
+ /** Base-2 logarithm of E. */
493
+ declare const LOG2E: number;
494
+ /** Base-10 logarithm of E. */
495
+ declare const LOG10E: number;
496
+
467
497
  /**
468
498
  * Fraction (rational number) implementation
469
499
  * @module @danielsimonjr/mathts-core/types/fraction
@@ -1683,4 +1713,4 @@ declare const math: {
1683
1713
 
1684
1714
  declare const VERSION = "0.1.0";
1685
1715
 
1686
- 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, DimensionMismatchError, type Dimensions, Dual, 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, MATHTS_CONVERSIONS, MATHTS_TYPES, type MathTSConfig, type MathTSValue, type MatrixBackend, type MatrixDimensions, type NumericType, type RoundingMode, SI_PREFIXES, type Scalar, type TypeDef, TypeRegistry, UNIT_ALIASES, Unit, type UnitDef, UnitParseError, VERSION, createFactory, createMathTSTyped, createTypedFunction, dim, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, isUnit$1 as isUnitValue, math, mathTyped, registerNativeTypes, registry };
1716
+ 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, DimensionMismatchError, type Dimensions, Dual, 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 NumericType, PHI, PI, type RoundingMode, SI_PREFIXES, SQRT1_2, SQRT2, type Scalar, TAU, type TypeDef, TypeRegistry, UNIT_ALIASES, Unit, type UnitDef, UnitParseError, VERSION, createFactory, createMathTSTyped, createTypedFunction, dim, getPrefix, getUnitDef, initTypedWasm, isArray, isBigInt, isBigNumber, isBoolean, isComplex, isDenseMatrix, isDual, isFraction, isFunction, isMatrix, isNull, isNumber, isObject, isSparseMatrix, isString, isTypedWasmAvailable, isUndefined, isUnit, isUnit$1 as isUnitValue, math, mathTyped, registerNativeTypes, registry };
package/dist/index.js CHANGED
@@ -644,6 +644,18 @@ function isDual(x) {
644
644
  return x instanceof Dual;
645
645
  }
646
646
 
647
+ // src/constants.ts
648
+ var PI = Math.PI;
649
+ var E = Math.E;
650
+ var TAU = 2 * Math.PI;
651
+ var PHI = (1 + Math.sqrt(5)) / 2;
652
+ var SQRT2 = Math.SQRT2;
653
+ var SQRT1_2 = Math.SQRT1_2;
654
+ var LN2 = Math.LN2;
655
+ var LN10 = Math.LN10;
656
+ var LOG2E = Math.LOG2E;
657
+ var LOG10E = Math.LOG10E;
658
+
647
659
  // src/types/fraction.ts
648
660
  function isFraction(value) {
649
661
  return value instanceof Fraction;
@@ -663,8 +675,17 @@ var Fraction = class _Fraction {
663
675
  numerator;
664
676
  denominator;
665
677
  constructor(numerator, denominator = 1n) {
666
- let num = typeof numerator === "bigint" ? numerator : BigInt(numerator);
667
- let den = typeof denominator === "bigint" ? denominator : BigInt(denominator);
678
+ const toRatio = (x) => {
679
+ if (typeof x === "number" && !Number.isInteger(x)) {
680
+ const f = _Fraction.fromNumber(x);
681
+ return [f.numerator, f.denominator];
682
+ }
683
+ return [typeof x === "bigint" ? x : BigInt(x), 1n];
684
+ };
685
+ const [pn, qn] = toRatio(numerator);
686
+ const [pd, qd] = toRatio(denominator);
687
+ let num = pn * qd;
688
+ let den = qn * pd;
668
689
  if (den === 0n) {
669
690
  throw new Error("Fraction denominator cannot be zero");
670
691
  }
@@ -3501,6 +3522,7 @@ export {
3501
3522
  DIMENSIONLESS,
3502
3523
  DimensionMismatchError,
3503
3524
  Dual,
3525
+ E,
3504
3526
  FRACTION_HALF,
3505
3527
  FRACTION_NEG_ONE,
3506
3528
  FRACTION_ONE,
@@ -3510,9 +3532,18 @@ export {
3510
3532
  Fraction,
3511
3533
  FunctionRegistry,
3512
3534
  I,
3535
+ LN10,
3536
+ LN2,
3537
+ LOG10E,
3538
+ LOG2E,
3513
3539
  MATHTS_CONVERSIONS,
3514
3540
  MATHTS_TYPES,
3541
+ PHI,
3542
+ PI,
3515
3543
  SI_PREFIXES,
3544
+ SQRT1_2,
3545
+ SQRT2,
3546
+ TAU,
3516
3547
  TypeRegistry,
3517
3548
  UNIT_ALIASES,
3518
3549
  Unit,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/mathts-core",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Core types, utilities, and configuration for MathTS",
5
5
  "author": "Daniel Simon Jr.",
6
6
  "license": "MIT",