3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Tim Mooney
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.
23 #include <gsl/gsl_ieee_utils.h>
24 #include <gsl/gsl_errno.h>
27 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
35 /* I'm not positive about AIX only supporting default precision rounding,
36 * but this is the best assumption until it's proven otherwise. */
38 case GSL_IEEE_SINGLE_PRECISION:
39 GSL_ERROR ("AIX only supports default precision rounding",
42 case GSL_IEEE_DOUBLE_PRECISION:
43 GSL_ERROR ("AIX only supports default precision rounding",
46 case GSL_IEEE_EXTENDED_PRECISION:
47 GSL_ERROR ("AIX only supports default precision rounding",
54 case GSL_IEEE_ROUND_TO_NEAREST:
58 case GSL_IEEE_ROUND_DOWN:
62 case GSL_IEEE_ROUND_UP:
66 case GSL_IEEE_ROUND_TO_ZERO:
75 /* Turn on all the exceptions apart from 'inexact' */
77 mode = TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW | TRP_UNDERFLOW ;
79 if (exception_mask & GSL_IEEE_MASK_INVALID)
80 mode &= ~ TRP_INVALID ;
82 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
88 GSL_ERROR ("AIX does not support the denormalized operand exception. "
89 "Use 'mask-denormalized' to work around this.",
93 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
94 mode &= ~ TRP_DIV_BY_ZERO ;
96 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
97 mode &= ~ TRP_OVERFLOW ;
99 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
100 mode &= ~ TRP_UNDERFLOW ;
102 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
104 mode |= TRP_INEXACT ;
108 mode &= ~ TRP_INEXACT ;
111 /* AIX appears to require two steps -- first enable floating point traps
113 fp_trap(FP_TRAP_SYNC);
115 /* next, enable the traps we're interested in */