GithubHelp home page GithubHelp logo

isq's Introduction

isq Travis build status Coverage Status Documentation Status

A javascript implementation of the International System of Quantities, ISO-80000.

The latest documentation can be read at Read the Docs.

Features

  • Uncertainty - SI.Quantity('123.456(4) km')
  • SI notation - SI.Quantity('1.234 56(4) × 10² km')
  • ASCII notation - SI.Quantity('1.234 56(4) x 10^2 km')
  • Conversion - SI.Quantity('25 m/s').to('km/h')
  • Symbolic expressions - SI.Quantity('W/(m² sr)')
  • Pluggable - SI.config.Number = require('big.js')

Getting started npm version

Install with npm

> npm install isq

Usage

Include the package

var SI = require('isq')

Create a number with SI.Number

var a = SI.Number(0.3),
    b = SI.Number('0.1'),
    c = SI.Number('0.03(1)'), // 0.03±0.01
    d = SI.Number(0.03, 0.01); // same as c

Create a quantity with SI.Quantity with an optional number and a unit

var a = SI.Quantity('1.03 kg'),
    b = SI.Quantity('1.03(1) kg') // 1.03±0.01 kg
    kg = SI.Quantity('kg'); // 1 kg

A Quantity is converted to a string with the toString() method. It uses a heuristic to determine the best symbol to use.

SI.Quantity('5 * 10^-6 s').toString()  // 5 µs
SI.Quantity('50 000 V/A').toString()   // 50 kΩ

Javascript does not allow overiding of operators, so named methods are used. The methods are also chainable. For example, the hypotenuse of a triangle is

var a = SI.Quantity('1.2 m'),
    b = SI.Quantity('80 cm'), // 0.8 m
    c = a.pow(2).plus(b.pow(2)).sqrt(); // ~ 1.44 m

Rounding errors

Rounding and precision errors are notorious in Javascript. For example 0.3 - 0.1 produces 0.19999999999999998 and NOT 0.2. ISQ can be configured to use a 'big number' package that avoids these issues.

SI.config.Number = require('big.js');
SI.Number(0.3).minus(SI.Number(0.1)) // 0.2

Uncertainty

Uncertainity, or margin of error, describes the imperfect nature of a measurement. Typically, it is the standard deviation of actual measurements. Anytime a calculation is performed, propagation of uncertainity is also performed to determine the uncertainty of the result.

let a = SI.Number('1.2(2)'),   // 1.2±0.2
    b = SI.Number('1.3(3)'),   // 1.3±0.3
    length = a.plus(b);        // 2.5±0.4

When comparing uncertain numbers, the uncertainity of both values is taken into consideration. Equality Is the difference of the two values within the resulting uncertainty?

License

The MIT license.

Copyright © 2015-2016 Richard Schneider ([email protected])

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.