Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The MCO library provides a means to correctly keep track of data without worrying about using their different units.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .npmignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Makefile
Octocat-spinner-32 README.md
Octocat-spinner-32 example.js
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
Octocat-spinner-32 sonar-project.properties
README.md

MCO

The software of the Mars Climate Orbiter (MCO) performed an incorrect calculation due to a conversion error between force in pounds and newton. Resulting, an erroneous trajectory was computed using this incorrect data and communication with the MCO was lost.

The MCO library provides a means to correctly keep track of measured data and conversion between data types without worrying about using different types/units.

MCO is loosely based on JSR-275. Concepts have been re-used from this library.

Travis-CI

Continuous integration using Travis-CI. Build is: Build Status

Example usage

The following snippet shows hot to create a unit/value of 10 [m], and divide it by 5 [s]. The result is 2 [m/s]:

    var metre = new mco.BaseUnit(mco.Quantity.LENGTH, 'm');
    var second = new mco.BaseUnit(mco.Quantity.TIME, 's');
    var unitValue1 = new mco.UnitValue(10, metre);
    var unitValue2 = new mco.UnitValue(5, second);

    var metrePerSecond = metre.divide(second);
    var result = unitValue1.divide(unitValue2);

Another snippet showing how to create a unit/value of 10 [km]:

    var kilometre = new mco.BaseUnit(mco.Quantity.LENGTH, mco.Prefix.KILO, 'm');
    var unitValue = new mco.UnitValue(10, kilometre);

Values of the same unit, but having another prefix are added correctly. The following snippet shows how to add 5 [m] to 10 [km], resulting in 10.005 [km]:

    var metre = new mco.BaseUnit(mco.Quantity.LENGTH, 'm');
    var kilometre = metre.setPrefix(mco.Prefix.KILO);
    var unitValue1 = new mco.UnitValue(10, kilometre);
    var unitValue2 = new mco.UnitValue(5, metre);

    var result = unitValue1.add(unitValue2);

Common transformers are already added to mco. For example, we can easily convert 100 [m] to [ft]:

    var metre = new mco.BaseUnit(mco.Quantity.LENGTH, 'm');
    var feet = new mco.BaseUnit(mco.Quantity.LENGTH, 'ft');
    var lengthMetre = new mco.UnitValue(100, metre);

    var result = mco.UnitTransformer.transform(lengthMetre, feet);

More examples can be found in the test/ directory.

Something went wrong with that request. Please try again.