• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

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

    履歴 編集

    macro
    <cmath>

    MATH_ERRNO

    # define MATH_ERRNO 1
    

    概要

    MATH_ERRNOは、<cmath>内でerrnoにエラーが設定されたかを表す整数定数マクロである。

    この定数とmath_errhandlingでビットANDをとった結果がゼロでないか比較することにより、errnoにエラーが設定されたか否かを判定できる。

    #include <iostream>
    #include <cmath>
    #include <cerrno>
    #include <cstring>
    
    int main()
    {
      errno = 0;
      std::acosh(0.1);
    
      if (math_errhandling & MATH_ERRNO && errno != 0) {
        std::cout << "math error : " << std::strerror(errno) << std::endl;
      }
      else {
        std::cout << "no error" << std::endl;
      }
    }
    

    出力例

    math error : Numerical argument out of domain
    

    バージョン

    言語

    • C++11

    処理系