- cmath[meta header]
- function[meta id-type]
- std[meta namespace]
- [mathjax enable]
- cpp17[meta cpp]
namespace std {
double
comp_ellint_1(double k); // (1) C++17
floating-point-type
comp_ellint_1(floating-point-type k); // (1) C++23
Promoted
comp_ellint_1(Arithmetic k); // (2) C++17
float
comp_ellint_1f(float k); // (3) C++17
long double
comp_ellint_1l(long double k); // (4) C++17
}
- Promoted[italic]
- Arithmetic[italic]
第1種完全楕円積分 (complete elliptic integral of the first kind) を計算する。
- (1) :
- C++17 :
double
に対するオーバーロード - C++23 : 浮動小数点数型に対するオーバーロード
- C++17 :
- (2) : 算術型に対するオーバーロード (対応する精度の浮動小数点数型にキャストして計算される)
- (3) :
float
型規定 - (4) :
long double
型規定
引数 k
の第1種完全楕円積分
$$
K(k) = F(k, \pi/2) = \int_0^{\pi/2} \frac{\mathrm d\theta}{\sqrt{1 - k^2 \sin^2 \theta}}
\quad \text{for } |k| \le 1
$$
を返す。
$ F(k, \phi) $ は第1種不完全楕円積分 (ellint_1
)。
- (1) : C++23では、拡張浮動小数点数型を含む浮動小数点数型へのオーバーロードとして定義された
#include <cmath>
#include <iostream>
int main() {
std::cout << "comp_ellint_1(0) = " << std::comp_ellint_1(0) << "\n"; // π / 2
std::cout << "comp_ellint_1(0.5) = " << std::comp_ellint_1(0.5) << "\n"; // 1.68575
std::cout << "comp_ellint_1(1) = " << std::comp_ellint_1(1) << "\n"; // ∞
}
- std::comp_ellint_1[color ff0000]
comp_ellint_1(0) = 1.5708
comp_ellint_1(0.5) = 1.68575
comp_ellint_1(1) = nan
単振り子の周期$ T
#include <iostream>
#include <cmath>
#include <iomanip>
constexpr double pi = 3.141592653589793;
constexpr double g = 9.80665;
double pendulum_period(double l, double theta) {
return 4.0 * std::sqrt(l/g) * std::comp_ellint_1(std::sin(theta/2.0));
}
double pendulum_period_shift(double theta) {
return (2.0 * std::comp_ellint_1(std::sin(theta/2.0))) / pi;
}
int main() {
std::cout << std::setprecision(16);
for (const auto theta : {15.0, 30.0, 45.0, 60.0}) {
const auto angle = theta * pi / 180.0;
std::cout << theta << " [°] : ";
std::cout << "T = " << pendulum_period(1.0, angle) << " [s], T/T0 = ";
std::cout << pendulum_period_shift(angle) << '\n';
}
}
- std::comp_ellint_1[color ff0000]
15 [°] : T = 2.015038014606197 [s], T/T0 = 1.004300579173466
30 [°] : T = 2.041338465858369 [s], T/T0 = 1.017408797595956
45 [°] : T = 2.08661217983496 [s], T/T0 = 1.039973343196804
60 [°] : T = 2.153242351783843 [s], T/T0 = 1.073182007149365
- C++17
- Clang: ??
- GCC: 7.1.0 [mark verified]
- ICC: ??
- Visual C++: ??
GCC 7.1.0–8.0.0 では定義域エラーが発生したときに std::numeric_limits::quiet_NaN
を返す。
- 第2種完全楕円積分
comp_ellint_2
- 第3種完全楕円積分
comp_ellint_3
- 第1種不完全楕円積分
ellint_1
- N3060 JTC1.22.29124 Programming Language C++ — Special Math Functions
- WG21 P0226R1 Mathematical Special Functions for C++17, v5
- ISO/IEC 29124:2010 Information technology -- Programming languages, their environments and system software interfaces -- Extensions to the C++ Library to support mathematical special functions
- 振り子 - Wikipedia
- P1467R9 Extended floating-point types and standard names
- C++23で導入された拡張浮動小数点数型への対応として、
float
、double
、long double
のオーバーロードをfloating-point-type
のオーバーロードに統合し、拡張浮動小数点数型も扱えるようにした
- C++23で導入された拡張浮動小数点数型への対応として、