cnum

Represent rational numbers in comfortably numeric way.

Usage no npm install needed!

<script type="module">
  import cnum from 'https://cdn.skypack.dev/cnum';
</script>

README

cnum - Comfortably Numbers

NPM Version NPM Downloads Build Status Build Size Code Coverage Scrutinizer Code Quality Language Grade GPL 3.0

Comfortably Numbers (cnum) represents rational numbers and related mathematical expressions in a biginteresting way.

Demo

CodePen Demo

Install

yarn add cnum

Usage

Build System

import {Rat} from 'cnum'

// a = 71/7
const a = new Rat(71, 7)

// b = 35/113
const b = new Rat(35, 113)

// c = a⋅b
const c = a.mul(b)

c.toString() // 355/113
c.valueOf() // 3.1415929203539825

Node

const {Rat} = require('cnum')
const r = new Rat(7, 11)
r.profile

Script Tags

<script src="https://unpkg.com/cnum"></script>
<script>
const r = new Rat(4, 13)
console.log(r.profile)
</script>

CodePen Demo

Command Line Interface

$ cnum "(5/7) + (2/3) ^ (5/9)"
42352677594770199369/28000000000000000000

$ cnum
cnum> 2/7
2/7 (≈0.28571428571428571429)

In Your Browser

Try with RunKit

Read the Docs

Documentation

CLI Commands

  • yarn install: Install dependencies
  • yarn dev: Run tests when source files are changed
  • yarn cli: Start a command line interface
  • yarn lint: Lint with ESLint
  • yarn test: Run Jest and Enzyme tests
  • yarn clean: Delete previous build
  • yarn docs: Build documentation
  • yarn build: Production build
  • yarn build-all: Production build all the things
  • yarn prepublish: Prepare for publishing
  • yarn publish: Publish to npm

Feedback