fesetround


fesetround

Sets the rounding direction in the floating-point environment

 #include <fenv.h> int fesetround ( int round  ); 

The fesetround( ) function sets the current rounding direction in the program's floating-point environment to the direction indicated by its argument. On success the function returns 0. If the argument's value does not correspond to a rounding direction, the current rounding direction is not changed.

Recognized values of the argument are given by macros in the following list, defined in fenv.h as integer constants. A given implementation may not define all of these macros if it does not support the corresponding rounding direction, and may also define macro names for other rounding modes that it does support.


FE_DOWNWARD

Round down to the next lower integer.


FE_UPWARD

Round up to the next greater integer.


FE_TONEAREST

Round up or down toward whichever integer is nearest.


FE_TOWARDZERO

Round positive values downward and negative values upward.

The function returns 0 if successful; a nonzero return value indicates that an error occurred.

Example

 /*  * Save, set, and restore the rounding direction.  * Report an error and abort if setting the rounding direction fails.  */ #pragma STDC FENV_ACCESS ON int prev_rounding_dir; int result; prev_rounding_dir = fegetround( ); result = fesetround( FE_TOWARDZERO ); /* ... perform a calculation that requires rounding toward 0 ... */ fesetround( prev_rounding_dir ); #pragma STDC FENV_ACCESS OFF 

See also the example for fmod( ) in this chapter.

See Also

fegetround( ), round( ), lround( ), llround( ), nearbyint( ), rint( ), lrint( ), llrint( )



C(c) In a Nutshell
C in a Nutshell (In a Nutshell (OReilly))
ISBN: 0596006977
EAN: 2147483647
Year: 2006
Pages: 473

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net