How does a calculator do trickier calculations?

I’ve got a working idea of how a calculator can add, subtract, multiply, and divide. But I’m puzzled by other functions, where it’s generally agreed that you’ll need a calculator… such as:

Trig functions
Non-integer exponents (including square roots)
Large exponents - My computer does 2[sup]400[/sup] in apparently the same amount of time it takes to do 2 * 400.

Also, if there is a pi button… is pi hard coded or is it derived each time you use it?

Your calculator has a tiny microprocessor and all operations, from simple addition to the most complex are just programmed subroutines. The value of pi will be kept in memory but getting it still requires a number of processor instructions. Even handling the keyboard requires a set of processor instructions. It is not complex but it is very involved as you have to break down everything into the simplest of machine instructions. The first microprocessor was invented and designed for a calculator.

Advanced functions like trigs, logs, and exponents are calculated over smallish ranges using interpolation functions. Usually polynomials. The most famous of which are the Taylor series for the given functions. However, the accuracy of Taylor’s is quite poor for the effort and better interpolation schemes are used. But if you look up “Taylor’s series” on the net you’ll get a general idea.

Once you have logs and “anti-log”, non-integer powering is simple.

The exponentiation does take considerably longer. But it’s far less than the time to take your finger off the “=” key, so you don’t notice.

Pi can be hardwired or it might be found via an inverse trig function. Don’t know.

Fun fact about early calculators: Some did multiplication by repeated adding and shifting. Not even using the grade school method. In base 10 too! Saved on silicon but the time was still plenty fast enough that the user wouldn’t care. You can do a lot in a millisecond.

And the programming isn’t always so good. Input the following into most calculators and you get the wrong answer:

2+34=20 (wrong)
2+3
4=14 (correct)

Interestingly if you do this using the built in calculator in Windows on your PC it gets the wrong answer when using Standard mode but the correct answer when using Scientific mode…go figure.

It pisses me off too because when I tell people the correct answer to the above problem is 14…people who have utterly forgotten their order of operations…they trot out their $5 solar powered calculator and ‘prove’ me wrong :rolleyes:.

I guess the moral of this is that if you are doing some advanced math on a calculator you might want to verify a problem or two by hand to be sure the manufacturer programmed the thing appropriately.

Most cheap calculators just accept a digit, then it clears for a function like adding or subtracting, then asks for the other digit, and the next function it assumes you wanted the answer to the last one displayed. So it’s doing 2+3=5. 5x4=20. Your better, scientific ones (~$15 and up to graphing calculators), that display your whole query on the same screen, then give the answer, expect you to use parentheses if you want to alter the order of operations.

Wow… It does. That is pretty mind-boggling to me.

Personally, I’m an RPN kind of guy and can’t stand most calculators.

Understood but I don’t think there is really an excuse for that today. The computational power necessary for a basic calculator is cheap…practically a commodity. An abacus probably costs more to make. It wouldn’t be hard for any modern calculator to remember your inputs and adjust the answer accordingly. So:

2+3* --displays–> 5
4= --displays–>14

Basically the calculator would review your string of inputs once the ‘=’ key is pressed and give the proper answer.

I do not think one or the other are right or wrong, just different.+ The fact that the windows calculator does both shows that rather than any mistake. When using a calculator I expect it to do 2+3=5 first and then multiply by 4. It is not “incorrect”. It is just one way of doing it and, in fact, the way most people expect which is probably why the normal calculator was programmed that way.

Pi is in the memory of most calculators. So are some important results such as cos pi.

And then there are the calculators that only accept reverse polish notation…

Microsoft is simply catering to the lowest common denominator with their standard calculator, probably based on the reasoning that people who are used to using calculators only for basic arithmetic would see 2+3*4 = 14 as an error, and add more fuel to the “MS is stupid and satanic” fire. They’re cutting down massively on their tech support calls this way, I’m sure.

Besides, if you notice, entering “2 + 3” into the standard mode will immediately show “5” on the display when you press the next operator. It’s being very clear about which method it’s using.

No…2+3*4=20 is definitely a wrong answer. Order of operations are not an obscure piece of mathematics that only scientists care about. They are a basic rule.

However, you may be correct that most people want to do 2+3 first and then multiply the result by 5. Still, that says more for sloppiness on the users part and failure of our education system to be clear on how to structure math problems. It may very well be a consumer thing now…regardless of what is ‘correct’ the 2+3*4=20 is what people expect so that’s what they get.

If you’ve been brought up on the system that normal calculators use it’s fine, but I must admit when your entering in along physics equation into a normal scientific calculator having to add all the brackets makes it easier to make a mistake.

I lost my programmble fraphics calculator, I was quite upset about this cos I know longer have justification to buy a new one as a normal scientific calculator will do for me at the moment, but it was alot easier to use as you could type in long equations so you could see the whole thing on the screen before you got the answer.

as written it’s wrong but as entered on the calculator, according to the rules that that calculator uses it is absolutly correct. When inputing information into a machine, you must input it in a way that the machine was made to handle it. You must convert your equation into the format
3*4+2 or else the machine has given you the correct answer but you have asked it the wrong question.

According to the rules of the calculator? Is it just me or shoud the calculator be made to conform to accepted mathematic principles laid down over thousands of years rather than adjusting mathematics to comply with how the calculator wants it done?

Again…I understand that as a practical matter the 2+3*4=20 on a calculator is here to stay but I don’t care how you slice it…that is still a wrong answer.

kanicbird: That’s just silly.

I can write a computer program in about ten minutes that handles an arbitrary infix math expression with the 4 standard operations and parentheses entered in to the console on a single line that would get processed the correct Order of Operations manner (BEDMAS/BODMAS, as you prefer).

For a bonus, I’ll do exponentials.

The calculator is absolutely no different, and in fact no calculator I’ve owned in the last 15 years has been so daft as to not follow the order of operations (I prefer infix over postfix/RPN, just out of habit).

No conversion of the equation is, or should be, necessary.

The only difference is in whether or not the calculator has been built to obey the standard order of operations.

kanicbird never said that programming was too limited to deal with order of operations, William_Ashbless. The question is how the program was designed to behave, whether or not that complies with standards.

The standard-mode Windows calculator is designed to ignore order of operations, and it does that admirably. Disagree with the designers, not with kanicbird.

stoyel: I agree. And the windows calculator is broken so far as i’m concerned. :slight_smile:

Nevertheless, kanicbird’s statement:

suggested to me that kanicbird implied that calculators simply work this way.

This was, perhaps, too strong an assumption, and for that I apologize.

But for what my opinion’s worth, calculators that don’t follow the order of operations are daft. :slight_smile:

Of course, according to Ken Iverson, 2*3+4 = 24, which is counter-intuitive whether you expect precedence or not … worse, 10 - 2 + 5 = 3.

(Ken Iverson was the creator of a programming language called APL, which had a number of interesting features for manipulating arrays, but not only had no operator precedence, it applied operators strictly right to left in the absence of parentheses).

Strictly speaking, we’d be a lot better off if we actually could retrain ourselves to think about expressions in prefix or postfix notation, rather than relying on the rather messy conventions we have for precedence rules. “2 3 + 4 *” and “2 3 4 * +” distinguish the two cases much better without recourse to precedence rules or parentheses, but thanks to the way we learned to do arithmetic, it seems alien. HP tried to retrain us with their early calculators, but it didn’t take.

(Actually, it was largely design considerations which made some early calculator manufacturers embrace RPN, but the point still stands.)

Actually, you get 14 if you type ‘2’, ‘+’, ‘3’, ‘’, ‘4’ ‘=’ onto a standard calculator anyway, it’s only if you type ‘2’, ‘+’, ‘3’, ‘=’, '’, ‘4’, ‘=’ you get 20.

Ah, I read it as a case of GIGO. :slight_smile: And the user doesn’t even get to vote on whether or not their data is garbage; it’s entirely up to the program.

I don’t like the way the Windows calculator behaves, either, but I do understand why the Powers that Be made that decision. (I’m sure the programmers were grinding their teeth.) If it’s that or answer five hundred calls from archly superior twerps who think they’ve found a bug in your software, well… sorry, standards, it was nice knowing you.

I would finish with some quip like ‘at least they know who their customers are,’ but… so help me, I actually like XP.