www.digitalmars.com [Home] [Search] [CTG] [RTL] [IDDE]

Last update Sep 16, 2002


fenv.h

fenv.h is the standard header providing access to the floating point environment.

Exceptions

The following exception flags expand to an integer value that is a power of 2.

Flag Description
FE_INEXACT Inexact result
FE_DIVBYZERO Divide by zero
FE_UNDERFLOW Underflow
FE_OVERFLOW Overflow
FE_INVALID Invalid operand or operation
FE_ALL_EXCEPT ORs all of the above exceptions

Rounding Modes

The following rounding modes each expand to a unique, positive constant of type int.

Mode Description
FE_TONEAREST Round to nearest value.
FE_UPWARD Round toward positive infinity.
FE_DOWNWARD Round toward negative infinity.
FE_TOWARDZERO Round toward zero; drop fraction.


Precision Modes

The following precision modes each expands to a unique constant of type int.

Mode Description
FE_FLTPREC Use float (32-bit) precision
FE_DBLPREC Use double (64-bit) precision
FE_LDBLPREC Use long double (80-bit) precision


feclearexcept

Header

fenv.h

Prototype

void feclearexcept(int excepts);

Description

Clears the exceptions specified by excepts.

Compatibility

C99 7.6.2.1

See Also

feraiseexcept

fegetexceptflag

Header

fenv.h

Prototype

void fegetexceptflag(fexcept_t *flagp, int excepts);

Description

Stores (in the structure pointed to by flagp) an implementation-specific representation of the exception flags specified by excepts. Type fexcept_t represents an exception flag.

Compatibility

C99 7.6.2.2

See Also

fesetexceptflag

feraiseexcept

Header

fenv.h

Prototype

int feraiseexcept(int excepts);

Description

Raises the exceptions specified by excepts.

Return Value

Returns a non-zero value if all exceptions specified by excepts are valid; otherwise, the return value is 0.

Compatibility

C99 7.6.2.3

See Also

feclearexcept

fesetexceptflag

Header

fenv.h

Prototype

void fesetexceptflag(const fexcept_t *flagp, int excepts);

Description

Sets the implementation-specific exception flags (from the structure pointed to by flagp) with the exception flags specified by excepts. *flagp should have been set by a previous call to fegetexceptflag; if not, the results are unpredictable. Type fexcept_t represents an exception flag.

Compatibility

C99 7.6.2.4

See Also

fegetexceptflag

fetestexcept

Header

fenv.h

Prototype

int fetestexcept(int excepts);

Description

Determines if any of the exceptions specified by excepts have been raised.

Return Value

The bitwise OR of the exceptions corresponding to the currently-raised exceptions specified by excepts. If none of the specified exceptions is raised, the return value is zero.

Compatibility

C99 7.6.2.5

See Also

fegetenv

fegetprec

Header

fenv.h

Prototype

int fegetprec(void);

Description

Gets the current precision mode.

Return Value

The current precision mode.

Compatibility

DOS Windows 3.x Phar Lap DOSX Win32

See Also

fesetprec

fesetprec

Header

fenv.h

Prototype

int fesetprec(int prec);

Description

Sets the precision mode to the value specified by prec. Precision mode has meaning only when inline coprocessor instructions are used; there is no affect without a coprocessor. When the program begins, the precision mode is FE_LDBLPREC.

Return Value

If prec is not one of the precision modes, fesetprec returns 0. Otherwise, it returns a non-zero value.

Compatibility

DOS Windows 3.x Phar Lap DOSX Win32

See Also

fegetprec

fegetround

Header

fenv.h

Prototype

int fegetround(void);

Description

Gets the current rounding mode. The value FLT_ROUNDS, declared in float.h, also evaluates to the current rounding mode.

Return Value

One of the rounding constants defined above.

Compatibility

C99 7.6.3.1

See Also

fesetround

fesetround

Header

fenv.h

Prototype

int fesetround(int round);

Description

Sets the rounding mode. The previous rounding mode is forgotten.

Return Value

Non-zero if successful; zero if invalid value given for round.

Compatibility

C99 7.6.3.2

See Also

fegetround

fegetenv

Header

fenv.h

Prototype

void fegetenv(fenv_t *envp);

Description

Copies the current floating-point environment (rounding mode, precision mode, and exceptions) into the buffer pointed to by envp.

Compatibility

C99 7.6.4.1

See Also

fesetenv

feholdexcept

Header

fenv.h

Prototype

int feholdexcept(fenv_t *envp);

Description

Copies the current floating-point environment (rounding mode, precision mode, and exceptions) into the buffer pointed to by envp, and resets the floating-point environment to the start-up state (round to nearest, no loss in precision, and no exceptions set).

Return Value

0 if successful, non-zero if not.

Compatibility

C99 7.6.4.2

See Also

feupdateenv

fesetenv

Header

fenv.h

Prototype

void fesetenv(const fenv_t *envp);

Description

Sets the current floating-point environment (rounding mode, precision mode, and exceptions) to the values stored in the buffer pointed to by envp.

Compatibility

C99 7.6.4.3

See Also

fegetenv

feupdateenv

Header

fenv.h

Prototype

void feupdateenv(const fenv_t * envp);

Description

Saves the current exceptions internally, sets the floating-point environment to the values stored in the buffer pointed to by envp, and then raises the saved exceptions.

Compatibility

C99 7.6.4.4

See Also

feholdexcept

Copyright © 1995-2002 Digital Mars. All Rights Reserved.