{"action":"created","issue":{"url":"https://api.github.com/repos/josdejong/mathjs/issues/680","repository_url":"https://api.github.com/repos/josdejong/mathjs","labels_url":"https://api.github.com/repos/josdejong/mathjs/issues/680/labels{/name}","comments_url":"https://api.github.com/repos/josdejong/mathjs/issues/680/comments","events_url":"https://api.github.com/repos/josdejong/mathjs/issues/680/events","html_url":"https://github.com/josdejong/mathjs/issues/680","id":163666536,"number":680,"title":"eval inequations with string scope","user":{"login":"boeni","id":20282164,"avatar_url":"https://avatars.githubusercontent.com/u/20282164?v=3","gravatar_id":"","url":"https://api.github.com/users/boeni","html_url":"https://github.com/boeni","followers_url":"https://api.github.com/users/boeni/followers","following_url":"https://api.github.com/users/boeni/following{/other_user}","gists_url":"https://api.github.com/users/boeni/gists{/gist_id}","starred_url":"https://api.github.com/users/boeni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boeni/subscriptions","organizations_url":"https://api.github.com/users/boeni/orgs","repos_url":"https://api.github.com/users/boeni/repos","events_url":"https://api.github.com/users/boeni/events{/privacy}","received_events_url":"https://api.github.com/users/boeni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-07-04T12:26:33Z","updated_at":"2016-08-15T13:25:32Z","closed_at":null,"body":"I'm using eval() in an nodejs project and it works great until i found this:\r\n```\r\n    print(math.eval('W<=5*Z', {W:'50',Z:'300'}));    // false\r\n    print(math.eval('W<=5*Z', {W:50,Z:300}));        // true\r\n```\r\nShouldn't the string scope eval the same way the number scope does?\r\n\r\nPS: I tried the code above also on\r\nhttp://jsbin.com/devacu/edit"},"comment":{"url":"https://api.github.com/repos/josdejong/mathjs/issues/comments/239800776","html_url":"https://github.com/josdejong/mathjs/issues/680#issuecomment-239800776","issue_url":"https://api.github.com/repos/josdejong/mathjs/issues/680","id":239800776,"user":{"login":"ThomasBrierley","id":12444321,"avatar_url":"https://avatars.githubusercontent.com/u/12444321?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomasBrierley","html_url":"https://github.com/ThomasBrierley","followers_url":"https://api.github.com/users/ThomasBrierley/followers","following_url":"https://api.github.com/users/ThomasBrierley/following{/other_user}","gists_url":"https://api.github.com/users/ThomasBrierley/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomasBrierley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomasBrierley/subscriptions","organizations_url":"https://api.github.com/users/ThomasBrierley/orgs","repos_url":"https://api.github.com/users/ThomasBrierley/repos","events_url":"https://api.github.com/users/ThomasBrierley/events{/privacy}","received_events_url":"https://api.github.com/users/ThomasBrierley/received_events","type":"User","site_admin":false},"created_at":"2016-08-15T13:25:31Z","updated_at":"2016-08-15T13:25:31Z","body":"I just found a use case for string comparison in my current project, although It's not reasonable to say it's within the scope of mathjs. However it highlighted to me that some type coercion is already being applied, maybe honing it's behaviour could solve this without sacrificing string operations.\r\n\r\nCoercion or Error happens when types do not match, also the behaviour of when and how is quite different to JavaScript. Using the string truths ```\"9\" > \"10\"``` and ```\"10\" < \"9\"``` I can illustrate which way things are being converted in different scenarios:\r\n\r\n```\r\nmath.eval(' \"9\" > x ', {x: 10}); // true (right symbol -> string)\r\nmath.eval(' 9 > x ', {x: \"10\"}); // Error (didn't try to coerce)\r\nmath.eval(' x < \"9\" ', {x: 10}); // false (right literal -> number)\r\nmath.eval(' x < 9 ', {x: \"10\"}); // Error (didn't try to coerce)\r\n```\r\n\r\nThere seems to be a difference between how symbols and literals are coerced and on what side of the operator they are. By comparison JavaScript doesn't appear to apply different rules between symbols and literals or which way around they are. It simply has a type preference depending on the operator.\r\n\r\n> You may expect the library to convert the numbers to BigNumbers and then add them up, which is not the case.\r\n\r\nI'm not sure I understand the implication of this. Would the result of the operation become a BigNumber? And would there be a difference if the inputs were converted BigNumbers first? or does it depend on the operation?"}}
{"actor":{"display_login":"ThomasBrierley"}}