#include #include #ifdef __MINGW32__ #include #endif #ifndef __MINGW32__ #define FE_TONEAREST 0x0000 #define FE_DOWNWARD 0x0400 #define FE_UPWARD 0x0800 #define FE_TOWARDZERO 0x0c00 /* 7.6.3.2 The fesetround function establishes the rounding direction represented by its argument round. If the argument is not equal to the value of a rounding direction macro, the rounding direction is not changed. */ int fesetround (int mode) { unsigned short _cw; if ((mode & ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO)) != 0) return -1; __asm__ volatile ("fnstcw %0;": "=m" (_cw)); _cw &= ~(FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO); _cw |= mode; __asm__ volatile ("fldcw %0;" : : "m" (_cw)); return 0; } /* 7.6.3.1 The fegetround function returns the value of the rounding direction macro representing the current rounding direction. */ int fegetround (void) { unsigned short _cw; __asm__ ("fnstcw %0;" : "=m" (_cw)); return _cw & (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | FE_TOWARDZERO); } #endif int main(int argc, const char **argv) { if (argc >= 2) { int nrm, n; n = sscanf (argv[1], "%i", &nrm); if (n == 1) switch (nrm) { case 0: case 0x400: case 0x800: case 0xc00: fesetround (nrm); } } printf ("Rmode $%08x\n", fegetround ()); printf("%0.2f\n", 0.105); printf("%0.2f\n", 0.115); printf("%0.2f\n", 0.125); printf("%0.2f\n", 0.135); return 0; }