Welcome Guest. Please Login or Register. Apr 5th, 2018, 10:57pm
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
If you require a dump of the post on your message board, please come to the support board and request it.
EVAL
« Thread started on: Dec 27th, 2011, 7:41pm »
Hi,
I'm making a calculator program, and to get the result I am using EVAL. Is there a way of giving EVAL an expression and it won't calculate it using BIDMAS?
Is there a way of giving EVAL an expression and it won't calculate it using BIDMAS?
One way would be to add parentheses in the appropriate places to force left-to-right evaluation. For example if you have the expression 'a + b * c ^ d' you could add brackets as follows: '((a + b) * c) ^ d' which would override the normal operator priority.
If you are building the expression step-by-step (as a calculator often would) this might be easy to arrange - just enclose the expression-so-far in brackets before you append the next term.
Alternatively you could parse the expression yourself and evaluate the individual operators separately rather than getting EVAL to do it. It's not particularly hard to do.
Incidentally some calculators do observe Order of Operations. This Wikipedia article states that Microsoft's calculator evaluates left-to-right in standard view but observes operator precedence in scientific view: