|
オイラー定数を求める(γ=0.57721566...)
OPTION ARITHMETIC NATIVE
LET S=0
LET N=1E+8
FOR I=1 TO N
LET S=S+1/I
NEXT I
PRINT S-LOG(N) !'およそ8桁
PRINT " .5772156649015328606065120"
END
---------------------------------------------------------------------------------------------
OPTION ARITHMETIC DECIMAL_HIGH
LET BETA=4.31913656629145
LET N=800
LET V=1
FOR K=1 TO INT(BETA*N)
LET V=V*N/K
LET S=S+(-1)^(K-1)*V/K
NEXT K
LET S=S-LLOG(N)
LET A=1
LET SS=1
FOR K=1 TO N-2
LET A=-A*K/N
LET SS=SS+A
NEXT K
LET S=S-LEXP(-N)/N*SS
LET SS=.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495146314472498070824809605040144865428362241739976449235362535003337429373377376739427925952582470949160087352039481656708532331517766115286211995015079847937450857057400299213547861466940296043254215190587755352673313992540129674205137541395491116851028079842348775872050384310939973613725530608893312676001724795378367592713515772261027349291394079843010341777177808815495706610750101619166334015227893586796549725203621287922655595366962817638879272680132431010476505963703947394957638906572967929601009015125195950922243501409349871228247949747195646976318506676129063811051824197444867836380861749455169892792301877391072945781554316005002182844096053772434203285478367015177394398700302370339518328690001558193988042707411542227819716523011073565833967348717650491941812300040654693142999297779569303100503086303418569803231083691640025892970890985486825777364288253954925873629596133298574739302
PRINT S !'およそ660桁
PRINT SS
PRINT USING "-%.##########^^^^^^":S-SS
!'LET A=4
!'LET B=5
!'DO
!' LET C=(A+B)/2
!' IF F(C)<0 THEN LET A=C ELSE LET B=C
!'LOOP UNTIL ABS(A-B)<1E-15
!'PRINT C
END
!'EXTERNAL FUNCTION F(X)
!'LET F=X*(LOG(X)-1)-2
!'END FUNCTION
EXTERNAL FUNCTION LLOG(X)
OPTION ARITHMETIC DECIMAL_HIGH
IF X<=0 THEN
CAUSE EXCEPTION 3004
ELSEIF X<1 THEN
LET LLOG=-LLOG(1/X)
ELSEIF X>3 THEN
LET LLOG=2*LLOG(SQR(X))
ELSE ! 1<=x<=3
LET H=(X-1)/(X+1) ! 0<=h<=0.5
LET T=0
LET N=1
LET K=H
LET H2=H^2
DO
LET T=T+K/N
LET N=N+2
LET K=K*H2
LOOP UNTIL K<=1E-1000
LET LLOG=2*T
END IF
END FUNCTION
EXTERNAL FUNCTION LEXP(X)
OPTION ARITHMETIC DECIMAL_HIGH
LET A=1
LET S=1
DO
LET I=I+1
LET A=A*X/I
LET S=S+A
LOOP UNTIL ABS(A)<1E-1000
LET LEXP=S
END FUNCTION
---------------------------------------------------------------------------------------------
OPTION ARITHMETIC DECIMAL_HIGH
LET N=5000
LET S=0
FOR I=1 TO N
LET S=S+1/I
NEXT I
LET S=S-1/2/N-LLOG(N)
LET A=1
FOR K=1 TO 210
LET A=A/N/N
LET S=S+BERNOULLI(2*K)/2/K*A
NEXT K
LET SS=.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495146314472498070824809605040144865428362241739976449235362535003337429373377376739427925952582470949160087352039481656708532331517766115286211995015079847937450857057400299213547861466940296043254215190587755352673313992540129674205137541395491116851028079842348775872050384310939973613725530608893312676001724795378367592713515772261027349291394079843010341777177808815495706610750101619166334015227893586796549725203621287922655595366962817638879272680132431010476505963703947394957638906572967929601009015125195950922243501409349871228247949747195646976318506676129063811051824197444867836380861749455169892792301877391072945781554316005002182844096053772434203285478367015177394398700302370339518328690001558193988042707411542227819716523011073565833967348717650491941812300040654693142999297779569303100503086303418569803231083691640025892970890985486825777364288253954925873629596133298574739302
PRINT S !'およそ690桁
PRINT SS
PRINT USING "-%.##########^^^^^^":S-SS
END
EXTERNAL FUNCTION LLOG(X)
OPTION ARITHMETIC DECIMAL_HIGH
IF X<=0 THEN
CAUSE EXCEPTION 3004
ELSEIF X<1 THEN
LET LLOG=-LLOG(1/X)
ELSEIF X>3 THEN
LET LLOG=2*LLOG(SQR(X))
ELSE ! 1<=x<=3
LET H=(X-1)/(X+1) ! 0<=h<=0.5
LET T=0
LET N=1
LET K=H
LET H2=H^2
DO
LET T=T+K/N
LET N=N+2
LET K=K*H2
LOOP UNTIL K<=1E-1000
LET LLOG=2*T
END IF
END FUNCTION
EXTERNAL FUNCTION BERNOULLI(K) !'ベルヌーイ定数
OPTION ARITHMETIC DECIMAL_HIGH
LET C=1
LET D=1
LET N=K/2
IF K=1 THEN
LET BERNOULLI=-1/2
ELSEIF MOD(K,2)=1 THEN
LET BERNOULLI=0
ELSE
FOR M=N TO 1 STEP-1
LET T=T+(-1)^M*D*M^(K-1)
LET C=C*(N+M+1)/(N-M+1)
LET D=D+C
NEXT M
LET BERNOULLI=-T*K/(2^K*(2^K-1))
END IF
END FUNCTION
---------------------------------------------------------------------------------------------
OPTION ARITHMETIC DECIMAL_HIGH
LET N=1150
LET BETA=4.97062575954423
LET A=1
LET H=1
FOR K=0 TO INT(BETA*N)
IF K>0 THEN
LET A=A*N*N/K/K
IF K>1 THEN LET H=H+1/K
END IF
LET AA=AA+A*H
LET BB=BB+A
NEXT K
LET C=1
LET CC=1
FOR K=1 TO 2*N
LET C=C*(2*K)*(2*K)*(2*K)/K/K/K/K/16/N/16/N
LET CC=CC+C
NEXT K
LET CC=CC/4/N
LET S=AA/BB-CC/BB/BB-LLOG(N)
LET SS=.5772156649015328606065120900824024310421593359399235988057672348848677267776646709369470632917467495146314472498070824809605040144865428362241739976449235362535003337429373377376739427925952582470949160087352039481656708532331517766115286211995015079847937450857057400299213547861466940296043254215190587755352673313992540129674205137541395491116851028079842348775872050384310939973613725530608893312676001724795378367592713515772261027349291394079843010341777177808815495706610750101619166334015227893586796549725203621287922655595366962817638879272680132431010476505963703947394957638906572967929601009015125195950922243501409349871228247949747195646976318506676129063811051824197444867836380861749455169892792301877391072945781554316005002182844096053772434203285478367015177394398700302370339518328690001558193988042707411542227819716523011073565833967348717650491941812300040654693142999297779569303100503086303418569803231083691640025892970890985486825777364288253954925873629596133298574739302
PRINT S !'およそ1000桁
PRINT SS
PRINT USING "-%.##########^^^^^^":S-SS
!'LET A=4
!'LET B=5
!'DO
!' LET C=(A+B)/2
!' IF F(C)<0 THEN LET A=C ELSE LET B=C
!'LOOP UNTIL ABS(A-B)<1E-15
!'PRINT C
END
!'EXTERNAL FUNCTION F(X)
!'LET F=X*(LOG(X)-1)-3
!'END FUNCTION
EXTERNAL FUNCTION LLOG(X)
OPTION ARITHMETIC DECIMAL_HIGH
IF X<=0 THEN
CAUSE EXCEPTION 3004
ELSEIF X<1 THEN
LET LLOG=-LLOG(1/X)
ELSEIF X>3 THEN
LET LLOG=2*LLOG(SQR(X))
ELSE ! 1<=x<=3
LET H=(X-1)/(X+1) ! 0<=h<=0.5
LET T=0
LET N=1
LET K=H
LET H2=H^2
DO
LET T=T+K/N
LET N=N+2
LET K=K*H2
LOOP UNTIL K<=1E-1000
LET LLOG=2*T
END IF
END FUNCTION
|
|