 The Museum of HP Calculators

HP Forum Archive 14

 Sin(Pi) in RadiansMessage #1 Posted by Mike on 27 Aug 2004, 8:21 a.m. I know the sine of pi in radians should be zero. However, 41CX -4.100 E-10 20S -2.067 E-13 30S 0.000 E00 I undererstand it has something to do with rounding, but the 30 does not calculate pi to infinity, does it round the answer instead? What about other models?

 Re: Sin(Pi) in RadiansMessage #2 Posted by John Limpert on 27 Aug 2004, 8:39 a.m.,in response to message #1 by Mike On the HP-28C and HP-48GX, sin(pi) results in zero (exactly).

 Re: Sin(Pi) in RadiansMessage #3 Posted by James M. Prange on 27 Aug 2004, 3:48 p.m.,in response to message #2 by John Limpert Yes, on the RPL calculators, replacing 'SIN(pi)' by 0 is one of the many built-in simplifications, as long as pi is symbolic. Of course, evaluating SIN(3.14159265359) quite correctly returns a non-zero result. To get the 0, clear both flag -2 (Constant -> symb) and flag -3 (Function -> symb). Regards,James

 Re: Sin(Pi) in RadiansMessage #4 Posted by Bram on 27 Aug 2004, 8:56 a.m.,in response to message #1 by Mike 11C: same answer as 41CX 32SII: same as 20S 29C: same as 20S 21: same as 30S (answer is correct: 0) Yhis last bit surprises me, because it fails to compute 2^30 correctly and almost all its successors are right on that point. Edited: 27 Aug 2004, 12:45 p.m. after one or more responses were posted

 Re: Sin(Pi) in RadiansMessage #5 Posted by JMH on 27 Aug 2004, 9:21 a.m.,in response to message #4 by Bram HP 97 same as the 41 and 11C -4.100 E-10

 Re: Sin(Pi) in RadiansMessage #6 Posted by Barry Schwartz on 27 Aug 2004, 1:09 p.m.,in response to message #4 by Bram In the manual for the 15C, it is explained that the value returned by using the PI key on the calculator is good to 10 significant digits. Thus the value returned for sin(PI) is the same as for the 41CX since it is the sin of a 10 digit approximation to PI rather than PI itself. Some calculators carry more than 10 digits in their calculations and thus will produce sin(PI) = 0 when they round to 10 digits. For example, the TI-83 produces sin(PI)=0 because it carries internal calculations to 14 digits. If one calculates sin(PI) on the TI-83 with the same 10 digit approximation used on the 15C, then the same result as the 15C is generated.

 Re: Sin(Pi) in RadiansMessage #7 Posted by Trent Moseley on 27 Aug 2004, 2:37 p.m.,in response to message #1 by Mike Of all the different calcs that I have only the 25C and the 31E give exactly zero. tm

 Re: Sin(Pi) in RadiansMessage #8 Posted by Gordon Dyer on 27 Aug 2004, 4:43 p.m.,in response to message #1 by Mike Here are my results: HP-45 sin(pi)= 0.000000000 HP-11C, HP-41CV, HP-41CX, V41 sin(pi)= -4.10E-10 HP-20S, 21S, 22S, 32SII, 42S, 71B sin(pi)= -2.06761537357E-13 HP-30S sin(pi)= 0 Casio fx-450 sin(pi)= 0 Commodore SR4912 sin(pi)= 0

 Re: Sin(Pi) in RadiansMessage #9 Posted by Emmanuel, France on 27 Aug 2004, 5:28 p.m.,in response to message #1 by Mike ```Casio FX-880P : 0 Sharp PC-1261 : 0 TI-59 : 0 HP-31E : -4,1000 -10 Elektronika MK-52 : 0 ```

 Re: Sin(Pi) in RadiansMessage #10 Posted by Wlodek Mier-Jedrzejowicz on 27 Aug 2004, 10:36 p.m.,in response to message #9 by Emmanuel, France How about approaching this as a mathematical problem? sin (pi-delta) = sin (delta) If delta is small and in radians then sin (delta) = delta, to a very good approximation. Now, no calculator can store pi completely accurately, there is always a difference "delta" between pi to the number of digits that the calculator uses and the true value. So, any calculator that does not round, or treat pi as a symbolic value, should give the answer sin (pi) = delta, where delta is this rounding error. Those calculators that do give zero are doing one of the following: Treating "pi" as a symbolic value, and recognizing that sin (pi) is exactly zero, _not_ calculating sin (pi). That is what HP's RPL calculators do in symbolic mode. Obtaining a non-zero value, but then displaying zero because of the display mode chosen (I am sure that is what gave zero for people who reported it on models such as the HP-31E or the HP20S). Rounding a small value to exactly zero. Some calculators do this "unthinkingly", which is Bad News, since many other calculations give small but non-zero values. That is why HP calculators do not round. Other calcs have code built in to recognize that certain types of calculation can reasonably be rounded, for example if an integer is followed by a string of zeros, and then a very small value. Casio and TI routinely do this sort of thing. The HP30S works to very high precision (almost 30 digits, it has been reported) and is more justified than most in rounding extremely small results to zero. There is one other possibility - that in the formulae I gave above delta is zero to the precision of the calculator. If you evaluate pi to enough significant digits, this will eventually happen. Just wait for calculators that work to, oh, a million or more significant figures... ;-) Hope this helps! Wlodek

 Re: Sin(Pi) in RadiansMessage #11 Posted by J-F Garnier on 28 Aug 2004, 5:31 a.m.,in response to message #10 by Wlodek Mier-Jedrzejowicz Actually, all Saturn-based machines know the pi value with double precision, and it's easy to get the extra pi digits thanks to the non-rounding behavior: SIN(3.1415926535) gives 8.97932384626e-11, which are the next pi digits: pi=3.1415926535897932384626... J-F

 Pi on Saturn-based calc'sMessage #12 Posted by Karl Schneider on 29 Aug 2004, 4:07 p.m.,in response to message #11 by J-F Garnier J-F Garnier posted, Quote: Actually, all Saturn-based machines know the pi value with double precision, and it's easy to get the extra pi digits thanks to the non-rounding behavior: SIN(3.1415926535) gives 8.97932384626e-11, which are the next pi digits: pi=3.1415926535897932384626... Ya lost me, there. I cannot obtain this result on any Pioneer, or RPL-based (28/48/49) calc that I have. I get -2.0676157357 x 10^(-13) when taking sine of the 12-digit approximation of pi on these calc's. When I convert 'pi' to a number on the RPL models and start "chipping away" the digits (Frac part, 10x, etc...), I stil find that only 12 digits of accuracy are present.

 Re: Pi on Saturn-based calc'sMessage #13 Posted by J-F Garnier on 30 Aug 2004, 6:39 a.m.,in response to message #12 by Karl Schneider Try SIN(3.1415926535), not SIN(3.14159265359) ... J-F

 Re: Pi on Saturn-based calc'sMessage #14 Posted by Karl Schneider on 31 Aug 2004, 1:06 a.m.,in response to message #13 by J-F Garnier J-F -- Mea culpa! OK, now I'm getting your results on the Saturn-based machines I mentioned in my last post. I had failed to follow your instructions exactly. In fact, it can be taken one digit further: ```sin (3.14159265358) = 9.79323846264 E-12 = 0.00000000000979323846264 ``` However, I believe that your mild "contradiction" of Wlodek: Quote: Actually, all Saturn-based machines know the pi value with double precision... is not strictly correct. This exercise proves only that the Saturn-based HP calculators' algorithm for sine can be used to calculate 12 additional significant digits of pi. It does not prove that the machines "know" the value of pi to 24 significant digits. As Wlodek stated, Quote: sin (pi-delta) = sin (delta) If delta is small and in radians then sin (delta) = delta, to a very good approximation. So, when the first N correct digits of pi are entered in "radians" mode, the sine function will yield the next 12 missing digits accurately (for 7 <= N <= 12, as it turns out). That is, the machines will crunch out the Taylor series (or whatever method it uses) accurately to 12 sigificant digits. Since there is no range overlap between the input and the output for this problem, up to the 24th significant digit can be obtained. This indicates, to me, a well-written algorithm that minimizes roundoff error. The algorithm could be: ```sin (x) = x - x3/3! + x5/5! - x7/7! + ... = a0 - a1 + a2 - a3 + ... with a0 = x a1 = a0 * (x/2)*(x/3) a2 = a1 * (x/4)*(x/5) a3 = a2 * (x/6)*(x/7) ... ``` Good problem! -- KS Edited: 31 Aug 2004, 1:22 a.m.

 Re: Sin(Pi) in RadiansMessage #15 Posted by Jordi Hidalgo on 28 Aug 2004, 12:28 p.m.,in response to message #10 by Wlodek Mier-Jedrzejowicz On the HP 9s, the sine of a number x such that 3.1415926535 <= x <= 3.1415926536 is zero in Radian mode. IMHO this is not fudging, but a way of using (defining) an irrational number by implementing one of its most important properties, namely: that its sine must be zero. And the same goes for the 9g and the 30S, with different intervals, though. Jordi

 Re: Sin(Pi) in RadiansMessage #16 Posted by Jordi Hidalgo on 29 Aug 2004, 11:50 a.m.,in response to message #15 by Jordi Hidalgo FWIW, here are the intervals around pi for which the sine function returns zero on the HP 30S: [3.141592653589793237976281, 3.141592653589793238945133] and on the HP 9g: [3.14159265358979323798, 3.14159265358979323894] Jordi

 Re: Sin(Pi) in RadiansMessage #17 Posted by Vieira, Luiz C. (Brazil) on 28 Aug 2004, 1:42 p.m.,in response to message #10 by Wlodek Mier-Jedrzejowicz Hello Wlodek, guys; just one single question, "bitte". I remember, when studying Calculus (long time ago), that: `sin(delta) = delta` but I cannot help remembering the math considerations/approaches and to what extent `sin(delta) = delta` I mean, how small should delta be so it is true. If `sin(delta) = delta` is true, then sin(delta) becomes a straight line and it cannot be asymptotic. Is it a math consideration or a numerical approach, what is, in fact, closer to computers? Just a doubt of mine. Cheers. Luiz (Brazil)

 Limit of 'delta'Message #18 Posted by Tizedes Csaba [Hungary] on 28 Aug 2004, 5:18 p.m.,in response to message #17 by Vieira, Luiz C. (Brazil) Dear Luiz, I hope I understood your question correctly. ```The Taylor-serie is: f(a+delta)=f(a)+ (n=0) f'(a)*delta/1!+ (n=1) f''(a)*(delta)^2/2!+ (n=2) f'''(a)*(delta)^3/3!+... (n=3, ...) Then we approximate f(x)=SIN(x), at a=0: --------------------------------- f(x)= SIN(x) and f(a)= 0 f'(x)= COS(x) and f'(a)= 1 f''(x)= -SIN(x) and f''(a)= 0 f'''(x)= -COS(x) and f'''(a)= -1 --------------------------------- f''''(x)=SIN(x), and so on... So, f(a+delta)==SIN(a+delta)==SIN(delta)=delta-(delta)^3/6+-... And we want to use this serie with n=1: SIN(delta)=delta+Rn(delta), where Rn(delta) is the residual: Rn(delta)=(delta-a)^(n+1)/(n+1)!*f[n+1](ksi), where f[n+1](ksi) is the (n+1)'th derivative of f(x) at ksi, where a<=ksi<=delta Use it, and find the maxima of Rn(delta): (n=1) Rn(delta)=(delta)^2/2!*f''(ksi), if we want to maximize it, we must to use f''(ksi)=1: so, let eps is the "precision of calculator": 1+eps<>1, we get: ########################################### # # # eps>=delta^2/2 --> delta<=SQRT(2*eps) # # # ########################################### On HP32SII: eps=5E-12, we get delta<=3.16E-6, and with simple trying I get delta=3.11E-6 ``` Best wishes: Csaba Edited: 28 Aug 2004, 5:22 p.m.

 Thanks, Tzedes and DaveMessage #19 Posted by Vieira, Luiz C. (Brazil) on 28 Aug 2004, 6:17 p.m.,in response to message #18 by Tizedes Csaba [Hungary] Hi, guys; I saw your post, Tizedes, and the Taylor-Series considerations brought some memories back... Thanks! Also, Dave's remark about the limits is precise: (sin(X))/X tends to be a straight line as X gets closer to zero. So, both numerical and analytical ways lead to a common situation. Thanks! This is the kind of thread that worth reading head to tail. Luiz (Brazil) Edited: 28 Aug 2004, 6:18 p.m.

 Re: Sin(Pi) in RadiansMessage #20 Posted by Dave Shaffer on 28 Aug 2004, 5:56 p.m.,in response to message #17 by Vieira, Luiz C. (Brazil) Note, also, that lim [sin(x)/x] = 1 as x-> 0 In other words, it IS linear the closer you get to zero.

 Re: Dave: Your post give me a new sight in calculus, thanks! [NT]Message #21 Posted by Tizedes Csaba [Hungary] on 28 Aug 2004, 6:22 p.m.,in response to message #20 by Dave Shaffer . Edited: 28 Aug 2004, 7:07 p.m.

 Re: Sin(Pi) in RadiansMessage #22 Posted by Garth Wilson on 28 Aug 2004, 6:17 p.m.,in response to message #17 by Vieira, Luiz C. (Brazil) To really understand what's going on, sometimes it's better to scrap all the mathematical proofs and just draw, in this case a right triangle with a very slim angle. You'll also see that as the angle approaches zero, the tangent will be the same as the sine. The equations are much more meaningful after we understand what they're representing.

 Re: Sin(Pi) in RadiansMessage #23 Posted by Palmer O. Hanson, Jr. on 30 Aug 2004, 9:34 p.m.,in response to message #22 by Garth Wilson I recall that in my old pre-calculus courses such as advanced algebra and trigonometry where the concept of limits and Taylor series had hardly been introduced there was a drawing of a sector defined by a radius R at an acute angle theta from the x axis, the length R along the x axis, and the arc of length R times theta. Then a vertical line was drawn from the intersection of the radius with the arc downward to the x axis (length is R sin theta) and another vertical line was drawn from the point (R,0) upward to connect with the extension of the radius (length is R tan theta). In this diagram the arc length is "squeezed" between the R sin theta segment and the R tan theta segment as the angle is decreased, showing that as the angle approaches zero the sin theta and the tan theta approach the angle theta. It's a lot easier to draw that than to write it, but I haven't learned how to post drawings.

 Re: Sin(Pi) in Radians and RoundingMessage #24 Posted by Palmer O. Hanson, Jr. on 30 Aug 2004, 11:21 p.m.,in response to message #10 by Wlodek Mier-Jedrzejowicz You state "Rounding a small value to exactly zero. Some calculators do this "unthinkingly", which is Bad News, since many other calculations give small but non-zero values. That is why HP calculators do not round. Other calcs have code built in to recognize that certain types of calculation can reasonably be rounded, for example if an integer is followed by a string of zeros, and then a very small value. Casio and TI routinely do this sort of thing." I am fairly familiar with the TI product line but not familiar with that. I know that the HP product carried guard digits and rounded results to ten digits. I also know that the TI product line routinely carried more digits in its results than were available in the display and rounded to the display. The internal results were typically truncated not rounded. TI switched to rounded internal results somewhere in the 1980's with the introduction of the TI-68 and TI-95. Can you give me some specific examples of the rounding that you describe?

 Re: Sin(Pi) in Radians and RoundingMessage #25 Posted by Jordi Hidalgo on 31 Aug 2004, 7:10 a.m.,in response to message #24 by Palmer O. Hanson, Jr. Palmer O. Hanson, Jr wrote: Quote:Can you give me some specific examples of the rounding that you describe? He might be referring to this posting by John H. Meyers (also in Datafile V15N6p30). Jordi

 Re: Sin(Pi) in RadiansMessage #26 Posted by Palmer O. Hanson, Jr. on 27 Aug 2004, 11:09 p.m.,in response to message #1 by Mike More on funny arithmetic On an HP-41 in radian mode: sin (pi) = - 4.1E-10 sin (-pi) = + 4.1E-10 sin (pi/4) - cos (pi/4) = 2.0E-10 On an HP-41 in degree mode: sin (180) = 0 sin (-180) = 0 sin (45) - cos (45) = 0 On a TI-59 in radian mode sin (pi) = 0 sin (-pi) = 0 sin (pi/4) - cos (pi/4) = 7.0E-13 On a TI-59 in degree mode: sin (180) = 0 sin (-180) = 0 sin (45) - cos (45) = 7.0E-13 On a TI-59: (pi x e) - (e x pi) = pi x 1 INV lnx - 1 INV lnx x pi = -2.8E-11, but pi / 1 INV lnx 1/x - 1 INV lnx x pi 1/x = -1.0E-12 It's enough to make one want to go back to one's slide rule where one KNEW that three digit accuracy was about the best one could do.

 Re: Sin(Pi) in RadiansMessage #27 Posted by Garth Wilson on 28 Aug 2004, 6:12 p.m.,in response to message #26 by Palmer O. Hanson, Jr. > It's enough to make one want to go back to one's slide rule where one KNEW that three digit accuracy was about the best one could do. The 3-4 digits of the slide rule were usually adequate for real applications too. Trying to guess at the width of the hairline impressed upon us how insignificant further digits really were. Without that reference, people now use a calculator with 10 digits or more, and are not satisfied that accuracy does not always match the extreme precision. Short of positioning a satelite, I can't think of anything that has any use for that many digits.

 other sin problemsMessage #28 Posted by hugh steers on 28 Aug 2004, 4:07 p.m.,in response to message #1 by Mike as you know, when you press pi on your hp then sin, most models return a non-zero answer. the manuals rather smugly point out that the answer returned is exactly the right answer for the pi approximation used by the machine. you know this. but, here is my swift kick in the pants for hp: how about getting the right answer for large arguments. for example, the 48gx gives sin(1e50) = 0.08683927... which is *completely* wrong, the correct answer being, -0.7.8967249342931008271028953... so there.

 Re: other sin problemsMessage #29 Posted by Mike on 28 Aug 2004, 5:11 p.m.,in response to message #28 by hugh steers sin is an offense to God, not HP, sine is something different

 Re: other sin problemsMessage #30 Posted by Dave Shaffer on 28 Aug 2004, 6:02 p.m.,in response to message #28 by hugh steers Hugh, re: "the 48gx gives sin(1e50) = 0.08683927... which is *completely* wrong, the correct answer being, -0.7.8967249342931008271028953..." Unless you are doing arithmetic to 50 digits, the poor calculator can't do this correctly. Without checking any actual algorithms, I strongly suspect that any calculator has to basically do MOD arithmetic to determine how many complete turns it has to subtract from x, and then determine the sine of the leftover. If the number of (implied) digits exceeds the calculator's number of sig figs, then the answer will be wrong. Your 1e50 means the calculator has to do 50 digit math to get the correct modulo remainder.

 Range ReductionMessage #31 Posted by John Limpert on 28 Aug 2004, 7:27 p.m.,in response to message #30 by Dave Shaffer It does bring up an issue with some implementations of trig. functions. Not all of them do a good job at range reduction. I ran across a mention of this problem while reading a book on computational astronomy (J. Meeus). The book uses the sine of 360000030 degrees as an example. The correct answer is 0.5.

 Re: Range ReductionMessage #32 Posted by Gordon on 30 Aug 2004, 6:44 p.m.,in response to message #31 by John Limpert The HP-42S does give sin(360000030)=0.5 !

 Re: other sin problemsMessage #33 Posted by hugh steers on 28 Aug 2004, 8:02 p.m.,in response to message #30 by Dave Shaffer not true. i had this problem already myself. you need a pi lookup table and you extract the appropriate 10 digit part (for 10 digit results). ok, you need to store the digits, but you dont need 50 digit math.

 Re: other sin problemsMessage #34 Posted by Eddie Shore on 29 Aug 2004, 2:58 p.m.,in response to message #28 by hugh steers I get 8.68392788E-2 for the HP20S. My TIs 89T and 36X both return ERROR. Go back to the main exhibit hall