Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      feraiseexcept

      From cppreference.com
      <c‎ |numeric‎ |fenv
       
       
       
       
      Defined in header<fenv.h>
      int feraiseexcept(int excepts);
      (since C99)

      Attempts to raise all floating-point exceptions listed inexcepts (a bitwise OR of thefloating-point exception macros). If one of the exceptions isFE_OVERFLOW orFE_UNDERFLOW, this function may additionally raiseFE_INEXACT. The order in which the exceptions are raised is unspecified, except thatFE_OVERFLOW andFE_UNDERFLOW are always raised beforeFE_INEXACT.

      Contents

      [edit]Parameters

      excepts - bitmask listing the exception flags to raise

      [edit]Return value

      0 if all listed exceptions were raised, non-zero value otherwise.

      [edit]Example

      Run this code
      #include <stdio.h>#include <fenv.h> #pragma STDC FENV_ACCESS ON void show_fe_exceptions(void){printf("current exceptions raised: ");if(fetestexcept(FE_DIVBYZERO))printf(" FE_DIVBYZERO");if(fetestexcept(FE_INEXACT))printf(" FE_INEXACT");if(fetestexcept(FE_INVALID))printf(" FE_INVALID");if(fetestexcept(FE_OVERFLOW))printf(" FE_OVERFLOW");if(fetestexcept(FE_UNDERFLOW))printf(" FE_UNDERFLOW");if(fetestexcept(FE_ALL_EXCEPT)==0)printf(" none");feclearexcept(FE_ALL_EXCEPT);printf("\n");} double some_computation(void){/* Computation reaches a state that causes overflow. */int r= feraiseexcept(FE_OVERFLOW|FE_INEXACT);printf("feraiseexcept() %s\n",(r?"fails":"succeeds"));return0.0;} int main(void){    some_computation();    show_fe_exceptions(); return0;}

      Output:

      feraiseexcept() succeedscurrent exceptions raised:  FE_INEXACT FE_OVERFLOW

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.6.2.3 The feraiseexcept function (p: 210)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.6.2.3 The feraiseexcept function (p: 191)

      [edit]See also

      clears the specified floating-point status flags
      (function)[edit]
      determines which of the specified floating-point status flags are set
      (function)[edit]
      C++ documentation forferaiseexcept
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/fenv/feraiseexcept&oldid=133795"

      [8]ページ先頭

      ©2009-2026 Movatter.jp