1 /* ieee-utils/fp-solaris.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
4 *
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.
9 *
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.
14 *
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.
18 */
19
20 #include <math.h>
21 #include <ieeefp.h>
22 #include "gsl_ieee_utils.h"
23 #include "gsl_errno.h"
24
25 int
gsl_ieee_set_mode(int precision,int rounding,int exception_mask)26 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
27 {
28 fp_except mode = 0 ;
29 fp_rnd rnd = 0 ;
30
31 switch (precision)
32 {
33 case GSL_IEEE_SINGLE_PRECISION:
34 GSL_ERROR ("solaris only supports default precision rounding",
35 GSL_EUNSUP) ;
36 break ;
37 case GSL_IEEE_DOUBLE_PRECISION:
38 GSL_ERROR ("solaris only supports default precision rounding",
39 GSL_EUNSUP) ;
40 break ;
41 case GSL_IEEE_EXTENDED_PRECISION:
42 GSL_ERROR ("solaris only supports default precision rounding",
43 GSL_EUNSUP) ;
44 break ;
45 }
46
47 switch (rounding)
48 {
49 case GSL_IEEE_ROUND_TO_NEAREST:
50 rnd = FP_RN ;
51 fpsetround (rnd) ;
52 break ;
53 case GSL_IEEE_ROUND_DOWN:
54 rnd = FP_RM ;
55 fpsetround (rnd) ;
56 break ;
57 case GSL_IEEE_ROUND_UP:
58 rnd = FP_RP ;
59 fpsetround (rnd) ;
60 break ;
61 case GSL_IEEE_ROUND_TO_ZERO:
62 rnd = FP_RZ ;
63 fpsetround (rnd) ;
64 break ;
65 default:
66 rnd = FP_RN ;
67 fpsetround (rnd) ;
68 }
69
70 /* Turn on all the exceptions apart from 'inexact' */
71
72 mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
73
74 if (exception_mask & GSL_IEEE_MASK_INVALID)
75 mode &= ~ FP_X_INV ;
76
77 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
78 {
79 /* do nothing */
80 }
81 else
82 {
83 GSL_ERROR ("solaris does not support the denormalized operand exception. "
84 "Use 'mask-denormalized' to work around this.",
85 GSL_EUNSUP) ;
86 }
87
88 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
89 mode &= ~ FP_X_DZ ;
90
91 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
92 mode &= ~ FP_X_OFL ;
93
94 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
95 mode &= ~ FP_X_UFL ;
96
97 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
98 {
99 mode |= FP_X_IMP ;
100 }
101 else
102 {
103 mode &= ~ FP_X_IMP ;
104 }
105
106 fpsetmask (mode) ;
107
108 return GSL_SUCCESS ;
109
110 }
111