/***********************************************************
cfint.c -- 連分数補間
***********************************************************/
Const N = 5 /* 点の数 */
Dim x[N], y[N] /* N 個の点の x 座標, y 座標 */

Sub maketable() /* 係数を求め y[] に上書き */

Dim i As Long, j As Long

j = 0
While j < N - 1
i=j+1
While i < N
y[i] = (x[i] - x[j]) / (y[i] - y[j])
i=i+1
Wend
j=j+1
Wend
End Sub

Function interpolate(t As Double) As Double /* 補間 */

Dim i As Long
Dim r As Double

r = y[N - 1]
i = N - 2
While i >= 0
r = (t - x[i]) / r + y[i]
i=i-1
Wend
interpolate = r
End Function


Const PI = 3.14159265358979323846264

#N88BASIC
Sub main()

Dim i As Long
Dim s As Double

For i = 0 To N-1 /* 表を作る */
x[i] = 20 * i
y[i] = Tan(x[i] * PI / 180)
Next
maketable()
i=0

While i <= 80 /* 補間 */
s = interpolate(i)
Print i, s, s - Tan(i * PI / 180)
i=i+1
Wend
End Sub
main()