问题
HP-UX's libc has the function fesetflushtozero to switch floating-point behavior between “gradual underflow” and “flush to zero”.
Despite combing through documentation and man pages of several Unix libc's (including glibc), I have yet to find how to achieve the same thing in other Unices. I'm particularly interest in Linux/glibc, Solaris and AIX.
回答1:
As you have doubtless noted, there’s no standard way to do this (for that matter, there’s no standard definition of “flush to zero”, nor any requirement that hardware implement it). So all of the means of doing this are platform-specific. To add a few more to the list, since this is a useful reference:
OSX / Intel:
fesetenv(_FE_DFL_DISABLE_SSE_DENORMS_ENV)
. Note that this only effects arithmetic done infloat
ordouble
, which is done using SSE2 (hence the name);long double
arithmetic is performed using the legacy x87 instructions, which do not support flushing.iOS / arm: On 32-bit ARM under iOS, flush-to-zero is the default mode. You can turn it off for VFP instructions (but not for NEON) by clearing the
__fpscr_flush_to_zero
bit in afenv_t
object and installing that environment withfesetenv( )
.iOS / arm64:
fesetenv(_FE_DFL_DISABLE_DENORMS_ENV)
.
回答2:
I'm wondering why the C99/UNIX standard function fesetround(FE_TOWARDZERO) isn't suitable for you - it's the same on all of these platforms, including HP/UX.
Platform-specific, you have:
- Linux glibc has the convenience function
fesetflushtozero()
:
http://www.gnu.org/software/libc/manual/html_node/Rounding.html - Solaris libm has a function
nonstandard_arithmetic()
to switch to zero-rounding:
http://docs.oracle.com/cd/E19957-01/806-3568/ncg_lib.html#2219
Couldn't find anything for AIX other than fesetround()
as per above.
来源:https://stackoverflow.com/questions/19877055/equivalent-of-fesetflushtozero-on-various-unices