/* Title: Test setjmp/longjmp rounding mode save/restsore File: testsetjmp.c Author: David N. Williams License: Public Domain Version: May 27, 2005 This code is intended to test whether setjmp() and longjmp() in a C99 system save and restore the IEEE 754 floating-point rounding control mode. The Single UNIX 3 Specification is silent on the issue, and there are indeed systems that implement either alternative. On our Mac OS X system we build the code this way: gcc -o testsetjmp testsetjmp.c With Linux we build it this way: gcc -lm -o testsetjmp testsetjmp.c Other systems may require linking with different libraries. */ #include #include #include jmp_buf mybuf; void change_round ( int round ) { fesetround ( round ); printf ("\nrounding direction changed to %i", fegetround() ); longjmp ( mybuf, 15 ); /* 15 just to see what happens */ } int main (void) { int status; printf ("\nrounding direction before setjmp is %i", fegetround() ); status = setjmp (mybuf); if ( status !=0 ) { printf ("\nstatus = %i", status); printf ( "\nrounding direction after longjmp is %i\n", fegetround() ); return 1; } change_round (FE_DOWNWARD); return 0; }