最終更新日時(UTC):
が更新

履歴 編集

variable
<numbers>

std::numbers::e(C++20)

namespace std::numbers {
  template <class T>
  inline constexpr T e_v = unspecified;    // (1)

  template <floating_point T>
  inline constexpr T e_v<T> = see below;   // (2)

  inline constexpr double e = e_v<double>; // (3)
}

概要

自然対数の底であるネイピア数を表す定数。

  • (1) : プライマリーテンプレート。これをインスタンス化するとプログラムは不適格となる
  • (2) : 任意の浮動小数点数型Tに対する定数定義。標準で定義される浮動小数点数型ごとの精度に応じた定数が定義される
  • (3) : double型に対する定数定義

#include <iostream>
#include <numbers>

int main()
{
  // double型定数
  double a = std::numbers::e;
  std::cout << a << std::endl;

  // 任意の浮動小数点数型の定数
  float b = std::numbers::e_v<float>;
  std::cout << b << std::endl;
}

出力

2.71828
2.71828

バージョン

言語

  • C++20

処理系