|
多倍長 LOG(2)を求める
前述の計算方法では別途、LOG(2)値が必要となる
計算式に
LOG((1+1/X)/(1-1/X))=LOG((X+1)/(X-1)=2*(1/X+1/(3*X^3)+1/(5*X^5)+1/(7*X^7)+...)
を使用し、以下の関係式
LOG(2) = 3 * LOG(81/80) + 5 * LOG(25/24) + 7 * LOG(16/15)
を使ってLOG(2)を求める。
なお、LOG(5)を直接求めるのなら、上の計算式と関係式
LOG(5) = 7 * LOG(81/80) + 4 * LOG(16/15) + 12 * LOG(10/9)
を使って求めることができる。
PUBLIC NUMERIC KETA,BIAS,EPS
INPUT PROMPT "桁数=":KETA
LET KETA=INT(KETA/4)
LET EPS=2
LET BIAS=0
LET KETA=KETA+EPS
OPTION BASE 0
DIM S(KETA),A(KETA),B(KETA),C(KETA),AA(KETA),BB(KETA),CC(KETA),M(KETA)
LET N = 1
LET A(0)=3
LET B(0)=5
LET C(0)=7
FOR I = 0 TO KETA - 1
LET R = A(I) - INT(A(I) / 161) * 161
LET A(I) = INT(A(I) / 161)
LET A(I + 1) = A(I + 1) + R * 10000
LET R = B(I) - INT(B(I) / 49) * 49
LET B(I) = INT(B(I) / 49)
LET B(I + 1) = B(I + 1) + R * 10000
LET R = C(I) - INT(C(I) / 31) * 31
LET C(I) = INT(C(I) / 31)
LET C(I + 1) = C(I + 1) + R * 10000
NEXT I
LET A(KETA) = INT(A(KETA) / 161)
LET B(KETA) = INT(B(KETA) / 49)
LET C(KETA) = INT(C(KETA) / 31)
MAT S=S+A
MAT S=S+B
MAT S=S+C
FOR I = KETA TO 0 STEP -1
IF S(I) >= 10000 THEN
LET R = INT(S(I) / 10000)
LET S(I)=S(I)-R*10000
LET S(I - 1) = S(I - 1) + R
END IF
NEXT I
DO
FOR I = 0 TO KETA - 1
LET R = A(I) - INT(A(I) / 25921) * 25921
LET A(I) = INT(A(I) / 25921)
LET A(I + 1) = A(I + 1) + R * 10000
LET R = B(I) - INT(B(I) / 2401) * 2401
LET B(I) = INT(B(I) / 2401)
LET B(I + 1) = B(I + 1) + R * 10000
LET R = C(I) - INT(C(I) / 961) * 961
LET C(I) = INT(C(I) / 961)
LET C(I + 1) = C(I + 1) + R * 10000
NEXT I
LET A(KETA) = INT(A(KETA) / 25921)
LET B(KETA) = INT(B(KETA) / 2401)
LET C(KETA) = INT(C(KETA) / 961)
MAT AA=A
MAT BB=B
MAT CC=C
LET N=N+2
FOR I = 0 TO KETA - 1
LET R = AA(I) - INT(AA(I) / N) * N
LET AA(I) = INT(AA(I) / N)
LET AA(I + 1) = AA(I + 1) + R * 10000
LET R = BB(I) - INT(BB(I) / N) * N
LET BB(I) = INT(BB(I) / N)
LET BB(I + 1) = BB(I + 1) + R * 10000
LET R = CC(I) - INT(CC(I) / N) * N
LET CC(I) = INT(CC(I) / N)
LET CC(I + 1) = CC(I + 1) + R * 10000
NEXT I
LET AA(KETA) = INT(AA(KETA) / N)
LET BB(KETA) = INT(BB(KETA) / N)
LET CC(KETA) = INT(CC(KETA) / N)
MAT S=S+AA
MAT S=S+BB
MAT S=S+CC
FOR I = KETA TO 0 STEP -1
IF S(I) >= 10000 THEN
LET R = INT(S(I) / 10000)
LET S(I)=S(I)-R*10000
LET S(I - 1) = S(I - 1) + R
END IF
NEXT I
FOR J = 0 TO KETA
IF S(J)<>M(J) THEN
MAT M = S
LET K=J
EXIT FOR
END IF
NEXT J
LOOP WHILE J<=KETA-EPS
MAT S=2*S
FOR I = KETA TO 0 STEP -1
IF S(I) >= 10000 THEN
LET S(I) = S(I) - 10000
LET S(I - 1) = S(I - 1) + 1
END IF
NEXT I
CALL WRITEDATA(S,"")
END
EXTERNAL SUB WRITEDATA(X(),Z$)
IF Z$="" THEN OPEN #1:TextWindow1 ELSE OPEN #1:NAME Z$
ERASE #1
FOR KK=-BIAS TO KETA
IF X(KK)<>0 THEN EXIT FOR
NEXT KK
PRINT #1:"SUB LN2(X())"
PRINT #1:"CALL LCLR(X)"
PRINT #1:"LET X(SIGN)=1"
PRINT #1:"FOR I=";STR$(KK);" TO KETA"
PRINT #1:"READ IF MISSING THEN EXIT FOR:X(I)"
PRINT #1:"NEXT"
PRINT #1:"DATA ";
FOR I=KK TO KETA-EPS-1
LET K=K+1
IF MOD(K,25)=0 THEN
PRINT #1:RIGHT$("000"&STR$(X(I)),4)
PRINT #1:"DATA ";
ELSE
PRINT #1:RIGHT$("000"&STR$(X(I)),4);
IF I<>0 THEN PRINT #1:",";
END IF
IF -BIAS<=0 AND I=0 THEN
PRINT #1
PRINT #1:"DATA ";
LET K=0
END IF
NEXT I
PRINT #1:RIGHT$("000"&STR$(X(KETA-EPS)),4)
PRINT #1:"END SUB"
CLOSE #1
END SUB
|
|