正接(タンジェント)の級数展開など種々の展開式の係数となる重要な数。

#N88BASIC

'最大公約数(the greatest common divisor)を求める関数
Function gcd(x As Double, y As Double) As Double
Dim t As Double

While y <> 0
t = fmod(x, y)
x = y
y = t
Wend
gcd = x
End Function

'浮動小数点剰余を求める
Function fmod(x As Double, y As Double) As Double
Dim i As DWord

If y = 0 Then
fmod = 0
Exit Function
End If

i = Int(x / y)
fmod = x - i * y
End Function

'計算機イプシロン(1 + eps =1 を満たさない最小の正の値)
Const SGL_EPSILON = 2.2204460492503e-16
Const DBL_EPSILON = 2.2204460492503e-16
Const N = 40
Dim i As Integer
Dim n As Integer
Dim q As Double
Dim b1 As Double
Dim b2 As Double
Dim d As Double
Dim t[N + 1] As Double

q = 1
t[1] = 1
For n = 2 To N
For i = 1 To n - 1
t[i - 1] = i * t[i]
Next i
t[n - 1] = 0
For i = n To 2 Step -1
t[i] = t[i] + t[i - 2]
Next i
If (n mod 2) = 0 Then
q = q * 4
b1 = n * t[0]
b2 = q * (q - 1)
If (b1 < 1 / DBL_EPSILON) And (b2 < 1 / DBL_EPSILON) Then
d = gcd(b1, b2)
b1 = b1 / d
b2 = b2 / d
Print "| B("; n; " | ="; b1; "/"; b2
Else
Print "| B("; n; " | ="; b1 / b2
End If
End If
Next n

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2010年01月25日 19:38