3 * Copyright (C) 2001 Henry Sobotka <sobotka@axess.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <gsl/gsl_ieee_utils.h>
22 #include <gsl/gsl_errno.h>
25 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
31 case GSL_IEEE_SINGLE_PRECISION:
32 _control87(PC_24, MCW_PC);
34 case GSL_IEEE_DOUBLE_PRECISION:
35 _control87(PC_53, MCW_PC);
37 case GSL_IEEE_EXTENDED_PRECISION:
38 _control87(PC_64, MCW_PC);
44 case GSL_IEEE_ROUND_TO_NEAREST:
45 _control87(RC_NEAR, MCW_RC);
47 case GSL_IEEE_ROUND_DOWN:
48 _control87(RC_DOWN, MCW_RC);
50 case GSL_IEEE_ROUND_UP:
51 _control87(RC_UP, MCW_RC);
53 case GSL_IEEE_ROUND_TO_ZERO:
54 _control87(RC_CHOP, MCW_RC);
57 _control87(RC_NEAR, MCW_RC);
60 /* Turn on all the exceptions apart from 'inexact' */
62 mode = EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW | EM_UNDERFLOW;
64 if (exception_mask & GSL_IEEE_MASK_INVALID)
67 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
68 mode &= ~ EM_DENORMAL;
70 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
71 mode &= ~ EM_ZERODIVIDE;
73 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
74 mode &= ~ EM_OVERFLOW;
76 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
77 mode &= ~ EM_UNDERFLOW;
79 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
88 _control87(mode, MCW_EM);