Bernoulli Numbers
01-28-2014, 09:21 PM
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Bernoulli Numbers
(12-18-2013 12:52 AM)Namir Wrote:  Bernoulli Numbers using Series Approximations

Hi Namir,

I think the RCL 00 in your line 31 should read RCL 01, right?

Then I tried my own implementation of this algorithm. I changed the way the tolerance is handled. If the user does not enter one, the current value in R01 is used. If this value is >=1 or <0, the tolerance defaults to 1E-5. Also the number of iterations is calculated beforehand so that the loop requires no tests and a simple DSE counter will do.

The following version uses only R00 - R02, and even R02 may be replaced with a stack register if the calculation of the factor starting at line 25 is placed behind the loop. Also no flags are required.

Code:
 01 LBL"BN" 02 RCL 01 03 "TOL=?" 04 PROMPT 05 FRC 06 LASTX 07 X=Y?   ' tolerance >=1 08 X<=0?  ' or =< 0 ? 09 1E-5   ' set default tolerance 10 STO 01 11 "N=?" 12 PROMPT 13 STO 00 14 1 15 RCL 00 16 X=Y? 17 -,5 18 X<0? 19 RTN 20 2 21 MOD 22 - 23 X=0? 24 RTN 25 RCL 00 26 FACT 27 PI 28 ST+ X 29 RCL 00 30 Y^X 31 / 32 ST+ X 33 RCL 01 34 RCL 00 35 1/X 36 CHS 37 Y^X 38 INT 39 STO 02   ' set number of iterations 40 CLX 41 ISG 02 42 LBL 01 43 RCL 02 44 RCL 00 45 CHS 46 Y^X 47 + 48 DSE 02 49 GTO 01 50 * 51 RCL 00 52 -4 53 MOD 54 SIGN 55 * 56 CHS 57 END

What do you think? Any errors or things to change?

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread Bernoulli Numbers - Namir - 12-18-2013, 12:52 AM RE: Bernoulli Numbers - Dieter - 01-28-2014 09:21 PM RE: Bernoulli Numbers - Dieter - 01-30-2014, 02:37 PM RE: Bernoulli Numbers - Namir - 01-30-2014, 09:34 PM

User(s) browsing this thread: 1 Guest(s)