BBC BASIC for Windows
« EVAL »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:52pm



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.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: EVAL  (Read 280 times)
JB91
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 47
xx 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?
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: EVAL
« Reply #1 on: Dec 27th, 2011, 9:45pm »

on Dec 27th, 2011, 7:41pm, JB91 wrote:
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:

http://en.wikipedia.org/wiki/Order_of_operations

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls