GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::fegetexceptflag - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. cfenv
  3. fegetexceptflag

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<cfenv>

std::fegetexceptflag(C++11)

namespace std {
  int fegetexceptflag(fexcept_t *flagp, int excepts);
}

概要

浮動小数点例外の現在の状態を、実装定義の表現で取得する。

この関数は、現在発生している浮動小数点例外のうち、指定された例外の集合のみを抽出して、実装定義の表現に変換して返す。

効果

ビット演算のORで複数指定された浮動小数点例外の種類exceptsの例外発生状態を、実装定義の表現に変換してflagpに書き込んで返す。

戻り値

実装定義の表現への変換および書き込みに成功したら0、そうでなければ0以外の値を返す。

例

// 標準C++の浮動小数点例外を、
// Visual C++での浮動小数点例外の形式に変換する
#include <iostream>
#include <cfenv>
#include <cfloat>

int main()
{
  float a = 1.0f;
  float b = 0.0f;
  float result = a / b;

  std::fexcept_t excepts = 0;
  std::fegetexceptflag(&excepts, FE_ALL_EXCEPT);

  if (excepts & _SW_ZERODIVIDE)
  {
    std::cout << "zero divided" << std::endl;
  }
}

出力例

zero divided

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 ✅
  • GCC: 4.3.0 ✅
  • Visual C++: 2013 ✅, 2015 ✅
    • コンパイルオプション/fp:strictまたは#pragma fenv_access (on)が必要。さもなくば、正しく動作しないおそれがある。
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.