# Time for a new calculator?

Discussion in 'Off-Topic' started by kdillinger, Jul 10, 2010.

1. ### kdillinger Thread Starter Active Member

Jul 26, 2009
141
3
I have a TI-86. It can calculate sin (2*pi) correctly but not sin(4*pi) or sin(6*pi), etc. etc.

sin(2*pi) is 0.
sin(4*pi) is -200e-15!

Ok, close enough to zero, but in electronics this can be a real calculation for capacitance, etc. I hope this does not creep into other calculations.

Maybe I need new batteries!

2. ### Wendy Moderator

Mar 24, 2008
21,417
2,948
Welcome to the wonderful world of truncating errors. 0 is almost -200e-15, isn't it?

A large part of computer science is based around these kind of problems.

3. ### ELECTRONERD AAC Fanatic!

May 26, 2009
1,146
16
I believe you have your calculator set in radians rather than degrees. After all, sin(2∏) = 0 rad or 0.1094°.

4. ### Wendy Moderator

Mar 24, 2008
21,417
2,948
Don't think so, not with such a small number (it really does approach zero as a limit). If it were degrees instead of radians it would be 0.109442606 (sin (2π)) or 0.217570395 (sin(4π)). The problem is the algorithm generating the answer isn't quite precise enough. It has nothing to do with batteries, and everything do to with how the answer is calculated inside the calculator.

On the old 8 bit computers it was possible to use simple math such as 2+2=3.9999998. Not that exact problem, but simple addition. There is a whole field devoted to these kinds of problems, it is core to computer science. Binary has quirks just like all number systems.

BTW, the sin of an angle is not in degrees (°), it is a dimensionless unit that is used to calculate length, a constant. The angle is either in degrees or radians.

Jul 7, 2009
1,585
142
There's nothing wrong with your calculator. This is an inherent problem in the numerical calculation -- the people who design the algorithms have to decide when "enough is enough" and stop iterating to get the answer. For example, here's a calculation of 10π done on a calculator set to calculate to 50 digits of precision (set to display 4 significant figures); the result is -5.841e-52, not zero as you would expect.

This is done with a high-quality math library (mpmath) and I just looked at their code to see how they do the calculation. They use a Taylor series for calculations with less than 600 digits of precision. Most calculators probably use the same strategy because the Taylor series for exp(x) will converge quickly, especially if you reduce the argument to lie within 0 to 2π. (If you weren't aware of it, the Taylor series for sin(x) and cos(x) are closely related to the series for exp(x).)

One could argue that the designers of these things should detect when the argument of a trig function like the sine is near 0 mod 2π. This would be easy to do, but then customers would also then start to expect you to handle other well-known multiples of π correctly. But, since your calculator also likely handles degrees and grads, you've got to handle those modes too. Pretty soon you'll start using up too much ROM space with all the checks.

More modern calculators that will handle symbolic expressions like sin(10π) can do the calculation correctly and return 0, as you expect. But even they will fail to return 0 if you first convert 10π to its (approximate) floating point form and then calculate the sine.

6. ### JoeJester AAC Fanatic!

Apr 26, 2005
3,912
1,742
Just for S&G's I did the sin(2pi) and sin(4pi) in excel. The sin function is normally in radians so i used the pi/180 to convert to degrees. Excel computes pi accurate to 15 digits. TI-98's pi is accurate to 12 digits.

sin ( 2 pi) = 2.4503e-16 radians and 4.27657e-18 degrees

Close enough is dictated by the task at hand. If they wanted you to end up with zero, which will be difficult since pi is neverending, they would have recommended the proper equipment to get that result.

7. ### Wendy Moderator

Mar 24, 2008
21,417
2,948

I tried my calculator, Casio fx-115MS, no hickups yet.

8. ### maxpower097 Well-Known Member

Feb 20, 2009
795
394
I've been using a great little calculator on my phone. Its an HD2 so its got a nice big LCD. But it has many modes for specific uses. I wrote the creator and he said he may make an electronics mode next.

9. ### tom66 Senior Member

May 9, 2009
2,613
218
My calculator is a fx-83GT+, it has natural VPAM, so if you ask it what sin(45 degrees) is it tells you it is sqrt(2).

10. ### Ghar Active Member

Mar 8, 2010
655
73
Technically you can never write Pi into a calculator in the first place since you have to end the digits somewhere so the answer should never be zero

11. ### Wendy Moderator

Mar 24, 2008
21,417
2,948
Most calculators get around this my having many more digits than they actually display. It is like Chaos theory, small changes have have large results, so it doesn't always work.

12. ### tom66 Senior Member

May 9, 2009
2,613
218
You can demonstrate the effect with a cheap pocket calculator (not a scientific one.) Enter '2', press sqrt twice, then square it (press the multiply button twice to square.) You won't get back '2'.