7.4.15 <fenv.h>

Provides access to the floating-point environment.

The following macros and functions are all implementation-defined.

Type

Definition Name

Description

Type
(macro)

fenv_t

Indicates the type of the entire floating-point environment.

fexcept_t

Indicates the type of the floating-point status flags.

Constant
(macro)

FE_DIVBYZERO

FE_INEXACT

FE_INVALID

FE_OVERFLOW

FE_UNDERFLOW

FE_ALL_EXCEPT

Indicates the values (macros) defined when the floating-point exception is supported.

FE_DOWNWARD

FE_TONEAREST

FE_TOWARDZERO

FE_UPWARD

Indicates the values (macros) of the floating-point rounding direction.

FE_DFL_ENV

Indicates the default floating-point environment of the program.

Function

feclearexcept

Attempts to clear a floating-point exception.

fegetexceptflag

Attempts to store the state of a floating-point flag in an object.

feraiseexcept

Attempts to generate a floating-point exception.

fesetexceptflag

Attempts to set a floating-point flag.

fetestexcept

Checks if floating-point flags are set.

fegetround

Gets the rounding direction.

fesetround

Sets the rounding direction.

fegetenv

Attempts to get the floating-point environment.

feholdexcept

Saves the floating-point environment, clears the floating-point status flags, and sets the non-stop mode for the floating-point exceptions.

fesetenv

Attempts to set the floating-point environment.

feupdateenv

Attempts to save the floating-point exceptions in the automatic storage, set the floating-point environment, and generate the saved floating-point exceptions.

 

feclearexcept

Attempts to clear a floating-point exception.

[Format]

#include <fenv.h>
long feclearexcept(long e);

[Parameters]

e Floating-point exception

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fegetexceptflag

Gets the state of a floating-point flag.

[Format]

#include <fenv.h>
long fegetexceptflag(fexcept_t *f, long e);

[Parameters]

f Pointer to area to store the exception flag state

e Value indicating the exception flag whose state is to be acquired

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

feraiseexcept

Attempts to generate a floating-point exception.

[Format]

#include <fenv.h>
long feraiseexcept(long e);

[Return values]

Normal: 0

Abnormal: Nonzero

[Parameters]

e Value indicating the exception to be generated

[Remarks]

When generating an "overflow" or "underflow" floating-point exception, whether the feraiseexcept function also generates an "inexact" floating-point exception is implementation-defined.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fesetexceptflag

Sets the state of an exception flag.

[Format]

#include <fenv.h>
long fesetexceptflag(const fexcept_t *f, long e);

[Parameters]

f Pointer to the source location from which the exception flag state is to be acquired

e Value indicating the exception flag whose state is to be set

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

Before calling the fesetexceptflag function, specify a flag state in the source location through the fegetexceptflag function.

The fesetexceptflag function only sets the flag state without generating the corresponding floating-point exception.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fetestexcept

Checks the exception flag states.

[Format]

#include <fenv.h>
long fetestexcept(long e);

[Parameters]

e Value indicating flags whose states are to be checked (multiple flags can be specified)

[Return values]

Bitwise OR of e and floating-point exception macros

[Remarks]

A single fetestexcept function call can check multiple floating-point exceptions.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fegetround

Gets the current rounding direction.

[Format]

#include <fenv.h>
long fegetround(void);

[Return values]

Normal: 0

Abnormal: Negative value when there is no rounding direction macro value or the rounding direction cannot be determined

[Remarks]

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fesetround

Sets the current rounding direction.

[Format]

#include <fenv.h>
#include <assert.h>
long fesetround(long rnd);

[Return values]

0 only when the rounding direction has been set successfully

[Remarks]

The rounding direction is not changed if the rounding direction requests through the fesetround function differs from the rounding macro value.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fegetenv

Gets the floating-point environment.

[Format]

#include <fenv.h>
long fegetenv( fenv_t *f);

[Parameters]

f Pointer to area to store the floating-point environment

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

feholdexcept

Saves the floating-point environment.

[Format]

#include <fenv.h>
long feholdexcept(fenv_t *f);

[Parameters]

f Pointer to the floating-point environment

[Return values]

0 only when the environment has been saved successfully

[Remarks]

When saving the floating-point function environment, the feholdexcept function clears the floating-point status flags and sets the non-stop mode for all floating-point exceptions. In non-stop mode, execution continues even after a floating-point exception occurs.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

fesetenv

Sets the floating-point environment.

[Format]

#include <fenv.h>
long fesetenv(const fenv_t *f);

[Parameters]

f Pointer to the floating-point environment

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

For the argument of this function, specify the environment stored or saved by the fegetenv or feholdexcept function, or the environment equal to the floating-point environment macro.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.

 

feupdateenv

Sets the floating-point environment with the previously generated exceptions retained.

[Format]

#include <fenv.h>
long feupdateenv(const fenv_t *f);

[Parameters]

f Pointer to the floating-point environment to be set

[Return values]

Normal: 0

Abnormal: Nonzero

[Remarks]

For the argument of this function, specify the object stored or saved by the fegetenv or feholdexcept function call, or the floating-point environment equal to the floating-point environment macro.

Do not use this function when compiler option nofpu is selected. If used, the function returns a nonzero value, which indicates an abnormality.