{"action":"created","issue":{"url":"https://api.github.com/repos/josdejong/mathjs/issues/548","labels_url":"https://api.github.com/repos/josdejong/mathjs/issues/548/labels{/name}","comments_url":"https://api.github.com/repos/josdejong/mathjs/issues/548/comments","events_url":"https://api.github.com/repos/josdejong/mathjs/issues/548/events","html_url":"https://github.com/josdejong/mathjs/issues/548","id":127664779,"number":548,"title":"Operators for Units and Numbers","user":{"login":"hgupta9","id":6797866,"avatar_url":"https://avatars.githubusercontent.com/u/6797866?v=3","gravatar_id":"","url":"https://api.github.com/users/hgupta9","html_url":"https://github.com/hgupta9","followers_url":"https://api.github.com/users/hgupta9/followers","following_url":"https://api.github.com/users/hgupta9/following{/other_user}","gists_url":"https://api.github.com/users/hgupta9/gists{/gist_id}","starred_url":"https://api.github.com/users/hgupta9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hgupta9/subscriptions","organizations_url":"https://api.github.com/users/hgupta9/orgs","repos_url":"https://api.github.com/users/hgupta9/repos","events_url":"https://api.github.com/users/hgupta9/events{/privacy}","received_events_url":"https://api.github.com/users/hgupta9/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-20T11:42:30Z","updated_at":"2016-01-20T14:01:26Z","closed_at":null,"body":"Brilliant syntax, whoever thought of bringing units directly into equations! The only thing that comes close (or goes further), is Google's math input.\r\n\r\nCurrently a few very simple unit expressions that fail to evaluate are:\r\n- 2 + 2 cm .... [fails](https://www.google.co.in/search?q=2%2B2+cm&oq=2%2B2+cm&es_sm=93&ie=UTF-8#q=2+%2B+2+cm+in+inch) in google\r\n- 2 cm + 2 .... [works](https://www.google.co.in/search?q=2%2B2+cm&oq=2%2B2+cm&es_sm=93&ie=UTF-8#q=2+cm+%2B+2+in+inch) in google\r\n\r\n>TypeError: Unexpected type of argument in function add (expected: Array or Matrix, actual: number, index: 1)\r\n\r\nCan these be supported by adding a Unit/Number and Number/Unit version into the add function? I'm really new to the library so I wanted to ask if such a thing is easily possible before messing with the code.\r\n\r\nThe way they would function\r\n- 2 + 2 cm\r\n  - adding 2 (Number) and 2 cm (Unit)\r\n     - since 2nd arg is Unit, add 2 to the Unit, resulting in 4 cm (Unit)\r\n- 2 cm + 2\r\n  - adding 2 cm (Unit) and 2 (Number)\r\n     - since 1st arg is Unit, add 2 to the Unit, resulting in 4 cm (Unit)"},"comment":{"url":"https://api.github.com/repos/josdejong/mathjs/issues/comments/173212453","html_url":"https://github.com/josdejong/mathjs/issues/548#issuecomment-173212453","issue_url":"https://api.github.com/repos/josdejong/mathjs/issues/548","id":173212453,"user":{"login":"ericman314","id":6345617,"avatar_url":"https://avatars.githubusercontent.com/u/6345617?v=3","gravatar_id":"","url":"https://api.github.com/users/ericman314","html_url":"https://github.com/ericman314","followers_url":"https://api.github.com/users/ericman314/followers","following_url":"https://api.github.com/users/ericman314/following{/other_user}","gists_url":"https://api.github.com/users/ericman314/gists{/gist_id}","starred_url":"https://api.github.com/users/ericman314/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericman314/subscriptions","organizations_url":"https://api.github.com/users/ericman314/orgs","repos_url":"https://api.github.com/users/ericman314/repos","events_url":"https://api.github.com/users/ericman314/events{/privacy}","received_events_url":"https://api.github.com/users/ericman314/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T14:01:26Z","updated_at":"2016-01-20T14:01:26Z","body":"Thanks, @hgupta9!\r\n\r\n`2 cm + 2` doesn't work by design. You could run into all kinds of ambiguities with something like `2 cm + 2 + 4 inch`. So we require the units to be included explicitly.\r\n\r\nIf you want to take a crack at messing with the code, see #426 for a similar discussion on this topic and example code to extend the `add` and `subtract` functions.\r\n\r\nAlso, when I click on your [second link](https://www.google.co.in/search?q=2%2B2+cm&oq=2%2B2+cm&es_sm=93&ie=UTF-8#q=2+cm+%2B+2+in+inch) google shows the query `2 cm + 2 in inch` and returns `(2 cm) + (2 in)`, not `(2 cm) + (2 cm)`. It's possible google is interpreting the `in` operator as an abbreviation for inches, then returns the result in inches. This is the equivalent expression in math.js:\r\n\r\n```\r\n2 cm + 2 in to inches\r\n2.78740157480315 inch\r\n```"}}