Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel: SIN(PI()) not = 0???? 1

Status
Not open for further replies.

Binary

Mechanical
May 16, 2003
247
Does anybody know why I'd get

Sin(pi()) = 1.22515 E-16 and Sin(2*pi()) = 2.4503 E-16 ?

For what it's worth, I get the same thing with Sin(radians(180)).

Sin(0), Sin(pi()/2), and Sin(3*pi()/2) all work.

I get the same type of problem (different magnitude and shifted 90°) with cosine.
 
Replies continue below

Recommended for you

Interesting given that setting PI = 3.14 gives a reasonable answer of 0.00159. As a comparison I ran:

sin(5) = -0.9589
sin (3) = 0.14112

Now thinking back to our calculus classes (ouch) the sine graph at pi was 0 for all practical purposes. So my guess is that 2 pi is next 0 of the sine graph from below the 0 line.

[tongue]

I've just checked my old faithful calculus text and guess what the graph of sine and cosine are in it. pi, 2pi, etc are graphed as 0 and cosine is at factors of pi/2, hence the 90 deg shift.

[thumbsup]

regards

sc
 
sorry forgot to mention that excel has a bit of a flaw in it for some reason when it comes to sin(PI()), etc.

I have asked MS about it once before and they basically shrugged the shoulders and said it doesn't really effect anything. Seems to be a very poor rounding error buried in excel.

sc
 
It can comes from the fact that PI is an infinite number. Since you can't use it as such, M$ had to use a finite value for PI, hence introducing calculus errors.

Also, I would think it can comes from the kind of number PI is assigned to (Real, Float, etc...) that might have an influence on calculus sharpness

Cyril Guichard
Mechanical Engineer
 
It's just a bit funny that Mathcad, my handheld calculator, and the MS desktop calculator all correctly show sin(pi)=0. It's a little irritating to have to include a ROUNDDOWN function so that I get zero and not tiny little exponential.

I'm just happy to know it's Excel and not my processor.
 
I've had similar rounding problems not related to sin(PI) that required workaround. The 1E-16 is not a huge error for calculations, but it WILL cause a LOOKUP function to return the wrong value. For example, I had a lookup table with rows "98" and "99", the Excel value to be looked up computed incorrectly to something like 98.999999999999999999 so it returned the data for 98, not 99. I now use the Round function a lot more to prevent such surprises...
 
It's causing me logical errors in things like IF statements.

I would've thought that MS would at least include their own rounding like they did in their windows desktop calculator.

It just goes to show that Excel was not designed as an engineering/scientific tool but as a business tool.
 
If you look at the calculation specs for Excel the smallest number it can handle is of the order of 10^-300.

They don't give a spec for the accuracy of the trig functions, that I could find.

I suspect that to force the answer to the expected one most people include an exception statement

sin(x)=if x=any_integer*pi then 0 else sin(x)

or so on.

Excel just lets you do the hard work!




Cheers

Greg Locock
 
Binary:

Those who made mathcad propably just inserted a special clause that ensures that mathcad returns 0 to sin(PI) no matter what.

Best regards

Morten
 
Actually, using the default settings for Mathcad, the numeric processor returns 1.2246E-16 for sin(pi). Similar to Excel, pi in the numeric processor is limited to about 15 decimal places.

The symbolic processor returns 0, because it knows that multiples of pi are supposed to return specific values.

TTFN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor