Skip to content

Instantly share code, notes, and snippets.

@CodeDrome
Created July 9, 2021 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeDrome/38344fc29eebcf229baaea9601b2d28e to your computer and use it in GitHub Desktop.
Save CodeDrome/38344fc29eebcf229baaea9601b2d28e to your computer and use it in GitHub Desktop.
mathjsunits06.js
function astronomical()
{
// create length units for astronomy
math.createUnit('lightyear', '9460730777119.56 km');
math.createUnit('parsec', '30856775714409.19 km');
math.createUnit('AU', '149597870.7 km');
// Proxima Centauri is the nearest star to the Sun
const EarthToProximaCentauri = math.unit(4.2465, 'lightyear');
output(`EarthToProximaCentauri: ${EarthToProximaCentauri}`);
output(`EarthToProximaCentauri.to('km'): ${EarthToProximaCentauri.to('km')}`);
output(`EarthToProximaCentauri.to('parsec'): ${EarthToProximaCentauri.to('parsec')}`);
output("<br>");
const EarthToSun = math.unit(1.0, 'AU');
output(`EarthToSun: ${EarthToSun}`);
output(`EarthToSun.to('miles'): ${EarthToSun.to('miles')}`);
output(`EarthToSun.to('miles').toNumber(): ${EarthToSun.to('miles').toNumber()}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment