Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

fegetround,fesetround

Feedback

In this article

Gets or sets the current floating-point rounding mode.

Syntax

int fegetround(void);int fesetround(int round_mode);

Parameters

round_mode
The rounding mode to set, as one of the floating-point rounding macros. If the value isn't equal to one of the floating-point rounding macros, the rounding mode isn't changed.

Return value

On success,fegetround returns the rounding mode as one of the floating point rounding macro values. It returns a negative value if the current rounding mode can't be determined.

On success,fesetround returns 0. Otherwise, a non-zero value is returned.

Remarks

Floating-point operations can use one of several rounding modes. These modes control which direction the results of floating-point operations are rounded toward when the results are stored. Here are the names and behaviors of the floating-point rounding macros defined in <fenv.h>:

MacroDescription
FE_DOWNWARDRound towards negative infinity.
FE_TONEARESTRound towards the nearest.
FE_TOWARDZERORound towards zero.
FE_UPWARDRound towards positive infinity.

The default behavior ofFE_TONEAREST is to round results midway between representable values toward the nearest value with an even (0) least significant bit.

The current rounding mode affects these operations:

  • String conversions.
  • The results of floating-point arithmetic operators outside of constant expressions.
  • The library rounding functions, such asrint andnearbyint.
  • Return values from standard library mathematical functions.

The current rounding mode doesn't affect these operations:

  • Thetrunc,ceil,floor, andlround library functions.
  • Floating-point to integer implicit casts and conversions, which always round towards zero.
  • The results of floating-point arithmetic operators in constant expressions, which always round to the nearest value.

To use these functions, you must turn off floating-point optimizations that could prevent access by using the#pragma fenv_access(on) directive prior to the call. For more information, seefenv_access.

Important

Prior to Windows 10 version 14393,fenv.h definedFE_UPWARD = 0x0100 andFE_DOWNWARD = 0x0200. In Windows version 14393, this header was updated to address a bug in which some APIs would interpretFE_UPWARD asFE_DOWNWARD, and vice-versa. Starting in Windows version 14393,FE_UPWARD = 0x0200 andFE_DOWNWARD = 0x0100, reversing their previous values.If you compiled your app against an old Windows SDK version (this issue depends on SDK version, not OS version or VS version) you might encounter this issue. Update your app to target the latest Windows SDK so that the definitions ofFE_UPWARD andFE_DOWNWARD are consistent with the Windows implementation. If you can't update your app to target a later Windows SDK, you can defineFE_UPWARD as0x0100 andFE_DOWNWARD as0x0200 in your code.

Requirements

FunctionC headerC++ header
fegetround,fesetround<fenv.h><cfenv>

For more information, seeCompatibility.

See also

Alphabetical function reference
nearbyint,nearbyintf,nearbyintl
rint,rintf,rintl
lrint,lrintf,lrintl,llrint,llrintf,llrintl


Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?