Created
July 9, 2021 16:44
-
-
Save CodeDrome/5540a95fcc4d8128c159a1b3f250708a to your computer and use it in GitHub Desktop.
mathjsunits05.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compatibility() | |
{ | |
// different types | |
const distance = math.unit(120, 'km'); | |
const temperature = math.unit(20, 'degC'); | |
const time = math.unit(60, 'minute'); | |
// here we are trying to add km and degC which | |
// is meaningless and will throw an exception | |
try | |
{ | |
output(`math.add(distance, temperature): ${math.add(distance, temperature)}`); | |
} | |
catch (e) | |
{ | |
output(`math.add(distance, temperature): ${e}`); | |
} | |
// dividing distance by time will give a result as km / minute | |
output(`math.divide(distance, time): ${math.divide(distance, time)}`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment