JSPM

dx-calc

0.2.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q34040F
  • License MIT

A math engine built in vanilla JS — zero dependencies, pure brainpower.

Package Exports

  • dx-calc
  • dx-calc/dxCalc.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dx-calc) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GitHub repo size GitHub License GitHub Issues

DXCalc Logo

DXCalc

A custom-built JavaScript math engine focused on precision, clarity, and full control. No dependencies. No borrowed logic. Just pure vanilla JS, crafted from scratch.

Features

  • Arbitrary-precision number handling (BigInt-friendly)
  • Core arithmetic: addition, subtraction, multiplication, division
  • Square root (in progress)
  • Planned: logarithms, exponentiation, trigonometry, parsing, memory stack
  • Eventually: graphical extension (plotting via canvas)

Philosophy

DXCalc is not meant to be a competitor to Decimal.js or Math.js. It’s an exercise in reinventing the wheel — fully self-developed, no lookups, no libraries. Every feature is designed, debugged, and refined from scratch as a personal learning journey.

The name

DXCalc is Decimal Class for standard base 10 numbers (from 0 to 9), that's why the roman 10 "X" in the name.

Why?

I started this project as part of The Odin Project, but it grew beyond a simple calculator. This is a math engine and it's teaching me how math, precision, and JavaScript really work under the hood. Every feature is born from the challenge of solving it unaided — this project is less about speed and more about understanding the why behind every result.

Method Input Expectations:

DXCalc.number(input):

  • Accepts string or number.

DXCalc.multiply(input):

  • string (recommended): Expected format for precise calculations.

  • number (not recommended): May lead to precision issues.

  • bigint: Supported, but the .value getter will return a string in decimal form when needed (e.g., for non-integer results).

DXCalc.number(x).sqrt():

  • Does not expect any input parameters.

Example Usage

To create a new instance of the DXCalc class, use the static DXCalc.number() method.

The DXCalc.number() method accepts a number, a bigint or a string representing a number.

  • Please refrain from inputting number type: DXCalc.number(3.14) → leads to warning (and subtle bugs) or may use octal or whatever representation.
import DXCalc from './path/to/dxCalc.js';

// Create a DXCalc number from a string
const num1 = DXCalc.number('-1.23');

// Example: Division
const num2 = '3.501';
const result = num1.divide(num2).value; // returns '-0.351328191945158'

// Don't do this: Multiplication with a warning about number-type input
DXCalc.number('2.25').multiply(0.000001).value; // Warning: Prefer string input for precision, returns '0.00000225'

// Example: Addition with high precision
const preciseSum = DXCalc.number('0.000000000000000000000000000000001')
  .add(DXCalc.number('0.000000000000000000000000000000002'))
  .value; // Returns '0.000000000000000000000000000000003'

Roadmap

For more detailed progress and future plans, see the DXCalc Project Board or explore the issues

Math Engine Core

  • DXCalc Class

  • Addition, Subtraction, etc.

  • Square Root

  • Logarithms

  • Exponentiation

Extended Features

  • Expression Parser

  • Constants (π, e)

  • Memory/Registers

  • Graphical Plotting (Canvas)

Smart Input

  • Word-based Input Parsing

Built solo with ❤️ by its-namami.