Giter VIP home page Giter VIP logo

notations's Introduction

Antimatter Dimensions Notations

NPM Codacy Badge

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

See them 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"
console.log(scientific.format("1e100", 2, 0));
// Outputs "1e100"
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 EmojiNotation 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.

Community Notations

To use community notations, download community pack from the releases page. The community pack can be used separately from the base pack. To access community notations from your code, use ADCommunityNotations instead of ADNotations. Apart from that, the usage pattern is the same as with the base pack

If you want your notation to be publicly available via this library, you should start by adding your notation to a src/community folder and making a pull request with it.

After your PR is merged (which means that one of the maintainers decided that it is good enough), you can reach out to AD devs about adding it to a base game. There is no guarantee that it will be added, but all well-made notations will be available as a community pack.

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 packs to the dist directory and to the docs directory.

npm run build

To build the AD pack or community pack separately, use build:ad or build:community command.

Contributing

  1. Be reasonable when commiting something.
  2. Be original when making a new notation.

Acknowledgements

Special thanks to the authors of notations:

Thanks to the authors of community notations:

Additional thanks to Omsi for the scaffolding of docs page.

notations's People

Contributors

buck4437 avatar dan-simon avatar dependabot-preview[bot] avatar dependabot[bot] avatar ducdat0507 avatar earthernsence avatar edricchan03 avatar ivansanchez avatar omsi6 avatar patashu avatar razenpok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

notations's Issues

Unit testing?

Unit tests can be used to verify that everything works as intended.

Add thorough testing for all non-community notations

The non-community notations are all meant to be high-quality and correctly implemented, yet they still sometimes have bugs or other surprising behavior. They should all have thorough testing done on them in the test suite to check that they work.

Hex notation rounds numbers when it shouldn't

E.g, 1.00000000001, which is 1 + 1e-11, is displayed as C0000000 (the same as 1), when in fact it should be displayed as (I believe) C1CDAF2C. This is caused by (new ADNotations.HexNotation()).modifiedLogarithm(new Decimal(1.00000000001)) being 0 (when it should be 1e-11). This is in turn caused by line 57 of src/hex.js, in the course of calculating the modified logarithm of new Decimal(1.00000000001), taking (new Decimal(1.00000000001)).toNumber(), which is 1 rather than, as might be expected, 1.00000000001. This is caused by the .toNumber method on Decimals doing rounding when the input is sufficiently close to an integer.

This rounding being desirable behavior for the .toNumber method in most cases, and numbers such as 1.00000000001 rarely if ever occurring in most likely use-cases of this library, this, though it's a bug, likely won't be fixed. Furthermore, as can be seen in the code of break_infinity.js (a comment starting on line 680 of src/break_infinity.ts as of this issue being created), writing a version of .toNumber such that new Decimal(x).toNumber() is an integer if and only if x is an integer for, say, all x between 0 and 1000, is surprisingly hard. Also, even if a number like 1.00000000001 does occur, it's reasonably likely that it is a misrounded version of 1 and showing it as C0000000 is the right thing to do. If there's enough outcry about this not being fixed, I might try to fix it anyway, though.

Dependabot script broke

I think this relates to

name: Merge Dependabot PR

on:
  pull_request:
    branches:
      - master

jobs:
  merge-me:
    name: Merge Dependabot PR
    runs-on: ubuntu-latest
    steps:
      - name: Merge Dependabot PR
        uses: ridedott/merge-me-action@master
        with:
          GITHUB_LOGIN: dependabot[bot]
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

and ridedott/merge-me-action#814 (saying "this method of using ridedott/merge-me-action broke") and https://github.com/ridedott/merge-me-action#usage (how to use ridedott/merge-me-action now). In other words, we're using ridedott/merge-me-action, the way in which we were doing it broke, and we can probably fix it by using a different syntax.

However, I don't understand enough about JS ecosystem to know exactly which new syntax to use. We're a public repository so we probably want to use the public repository advice, which seems like we want to switch to something like:

on:
  workflow_run:
    types:
      - completed
    workflows:
      # List all required workflow names here.
      - 'Continuous Integration'

rather than pull request, and also switch to v2. However, something seems pretty suspicious here and I'd probably want to do more research (why v2 instead of master?). Also, IDK if our workflow is called "Continuous Integration".

fixMantissaOverflow should not round up

The current implementation of fixMantissaOverflow seems to always round up (when the first non-significant digit is 5), as noted on

expect(notation.format(34.5, 0)).toBe("35₀"); // Is the rounding right??
expect(notation.format(33.5, 0)).toBe("34₀"); // Is the rounding right??

I think it'd be better to implement the "round half to even" algorithm (see also the IEEE754 stuff about rounding).

In a nutshell:

A tie-breaking rule without positive/negative bias and without bias toward/away from zero is round half to even. By this convention, if the fractional part of x is 0.5, then y is the even integer nearest to x. Thus, for example, +23.5 becomes +24, as does +24.5; while −23.5 becomes −24, as does −24.5. This function minimizes the expected error when summing over rounded figures, even when the inputs are mostly positive or mostly negative.

Nonzero Decimals under Number.MIN_VALUE are treated as zero

This is (I believe) due to formatUnder1000 being called and the Decimals being converted to number. It's only apparent for hex notation; on the demos page, 1e-324 isn't formatted as 80000000, but 1e-325 is formatted as 80000000. However, (new ADNotations.HexNotation()).formatDecimal(new Decimal('1e-325')) isn't 80000000. (It seems to me that in scientific notation, sufficiently small numbers should perhaps be formatted with negative exponents, contrary to what currently appears to be the case; however, that should probably be a separate issue.)

I don't want to try to fix this until I know whether it's considered important enough to fix and whether other notations that can use negative exponents (mostly scientific and its close relatives, but also logarithm and arguably brackets and roman) should also format small numbers differently.

some inputs hangs the demos page

anything that starts with "e" or has a decimal number in the exponent (after an e) will break when the parser reaches prime notation.

Wrong notation output

I enter ee6,mixed scientific is display 1.00e1.000e6
But I play antimatter dimensions,it display 1.00e1.000 M
Screenshot_20191203-154145_Samsung Internet

Scientific notation formatting issue

Is your feature request related to a problem? Please describe.
Some examples: 1e1.5e12 => 1e2e12
1e7.4e13 => 1e7e13

Describe the solution you'd like
Rounding of Y in XeYeZ should be at least 2 dp, or have an additional parameter that specifies the precision.

github.io page is broken

This appears to be called by ad-notations.min.js trying to use tslib, which it can't because tslib is not defined.

TypeError: t.indexOf is not a function when using node.js

Steps to reproduce:

  • npm init
  • npm i @antimatter-dimensions/notations break_infinity.js

installed Packages:

  • "@antimatter-dimensions/notations": "^3.0.3",
  • "break_infinity.js": "^2.0.0"

Test Script:

const Decimal = require("break_infinity.js");
const ADNotations = require("@antimatter-dimensions/notations")

const notation = new ADNotations.StandardNotation();

console.log(notation.formatDecimal(new Decimal(1)));

Trace (.\ is project root):

TypeError: t.indexOf is not a function
    at t.fromString (.\node_modules\break_infinity.js\dist\break_infinity.common.js:1:6465)
    at new t (.\node_modules\break_infinity.js\dist\break_infinity.common.js:1:743)
    at i (.\node_modules\break_infinity.js\dist\break_infinity.common.js:1:243)
    at t.div (.\node_modules\break_infinity.js\dist\break_infinity.common.js:1:10392)
    at .\node_modules\@antimatter-dimensions\notations\dist\ad-notations.umd.js:106:24
    at StandardNotation.formatDecimal (.\node_modules\@antimatter-dimensions\notations\dist\ad-notations.umd.js:413:110)
    at Object.<anonymous> (.\index.js:6:22)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

Imperial ends before e9e15

Currently, imperial doesn’t display values correctly past a certain point (around 1e6.7e11). Hence, some adjectives need to be added.

Suggestions:

‘Microscopic’ - before minute
‘Meager’ - between small and modest
‘Abundant’ - between large and great
‘Expansive’ - between large and great (after abundant?)
‘Grand’ - between great and huge
‘Immense’ - between gigantic and colossal
‘Endless’ - after cosmic

prime notation is wrong

notations/src/prime.ts

Lines 59 to 63 in ca22e02

// If the number is smaller than maxInt, 10006, then we just find the primes and
// format them.
// If not we need a way of representing the number, using only primes of course.
// So we derive an exponent that will keep the base under the maxInt, then
// we derive prime factors for both and format them as (base)^(exponent).

First, this is wrong- it will produce "factorizations" that are not equal to the original number. Second, 10k is ridiculously low! You hardly ever see numbers that low in antimatter dimension.

I realize that this is intended to be a shorthand, so 10007 is written "(2²×5²)^(2)" in prime notation for the same reason that it is written "1.00e4" in scientific. I also realize that integer factorization is in NP and that you have to cut corners at some point in favor of gameplay.

However, incorrect factorizations that doesn't even share any factors with the original number is borderline offensive! Can we do better?

Feature request: SI prefixes notation

I'd like to have notations using the prefixes from the international system of units, i.e.:

k M G T P E Z Y R Q B

Or their long forms:

Kilo Mega Giga Tera Peta Exa Zetta Yotta Ronna Quecca Bundecca

Note that I'm including the proposal for Ronna and Quecca, as well as the hypothetical Bundecca.

I guess that a nice approach would be to add this as a setting, and letting the abbreviate function use either the "standard" list (K M B T Qa Qt Sx Sp Oc No Dc, etc), the "short SI" list (k M G T P E Z Y R Q B) or the "long SI" list (Kilo Mega Giga Tera Peta Exa Zetta Yotta Ronna Quecca Bundecca). I don't see a need to add whole new notations, but rather change how the ones using the "standard" suffixes work.

There's also a proposal to extend the SI prefixes up to 10^48, which boils down to

k M G T P E Z Y kY MY GY TY PY EY ZY YY

Arguably this could be extended like...

k M G T P E Z Y R Q B kB MB GB TB PB EB ZB YB RB QB BB kBB MBB GBB TBB PBB EBB ZBB YBB RBB QBB BBB kBBB

...and later, add an exponent to the Bundeccas (to support those insane 1e9999999999 numbers), like

MB² = MBB
MB³ = MBBB
MB⁴ = MBBBB

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.