8000 GitHub - PitherBro/notations: Notations used in Antimatter Dimensions
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PitherBro/notations

 
 

Repository files navigation

Antimatter Dimensions Notations

All the notations that are included in current version of Antimatter Dimensions and the upcoming Reality Update.

See it in action here

Setup

CDN

The simplest way to use this package is to include these scripts in your HTML page:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/break_infinity.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@antimatter-dimensions/notations"></script>

You can also grab specific versions here:

npm

npm install @antimatter-dimensions/notations

There is no default export. The correct way to import notations is:

import * as ADNotations from "@antimatter-dimensions/notations";

Use

All the notations are included inside ADNotations object:

const scientific = new ADNotations.ScientificNotation();

The main method that notations provide is format(value, places, placesUnder1000)

  • value can be Decimal, number or string which you want to format
  • places is used to format mantissa when number is greater than 1000
  • placesUnder1000 is used to format the number when it is lesser than 1000
const scientific = new ADNotations.ScientificNotation();

// Outputs "1000.00"
console.log(scientific.format(1000, 2, 2));
// Outputs "1.00e100,000"
console.log(scientific.format("1e100", 2, 0));
// Outputs "1e100,000"
console.log(scientific.format(new Decimal(1e100), 0, 0));

You can configure some formatting aspects via ADNotations.Settings object:

const scientific = new ADNotations.ScientificNotation();

// Outputs "1e100,000"
console.log(scientific.format("1e100000", 2, 2));

// Outputs "1e100000"
ADNotations.Settings.exponentCommas.show = false;
console.log(scientific.format("1e100000", 2, 2));

// Outputs "Infinite"
ADNotations.Settings.isInfinite = decimal => decimal.gte(1e100);
console.log(scientific.format(1e101, 2, 2));

Configuration settings:

  • Settings.isInfinite - function that determines if a Decimal value is infinite (default is decimal => decimal.gte(Decimal.MAX_VALUE))
  • Settings.exponentCommas.show - show commas in formatted output (default is true)
  • Settings.exponentCommas.min - lower bound for exponent to be formatted with commas (default is 100000)
  • Settings.exponentCommas.max - upper bound for exponent to be formatted with commas (default is 1000000000)

Extend

Creating your own notations is very simple! Just extend base class Notation and implement the required methods get name() and formatDecimal:

class SimpleNotation extends ADNotations.Notation {
  get name() {
    return "Simple";
  }

  formatDecimal(value, places) {
    return `Mantissa: ${value.mantissa.toFixed(places)}, Exponent: ${value.exponent}`;
  }
}

You can also extend existing notations (like CancerNotation does) and override other methods, but this is a more advanced case which you can figure out by looking at the source code of existing notations.

Build

First, clone the repo

git clone https://github.com/antimatter-dimensions/notations.git
cd notations

Then install npm dependencies

npm install

And then run build command which will build all targets to the dist directory.

npm run build

Acknowledgements

Special thanks to the authors of notations:

Additional thanks to https://github.com/omsi6 for the scaffolding of docs page.

About

Notations used in Antimatter Dimensions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 94.1%
  • JavaScript 5.9%
0