Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / ieee-utils / fp-openbsd.c
1 /* fp-openbsd.c
2  * 
3  * Copyright (C) 2001 Jason Beegan
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 <ieeefp.h>
21 #include <gsl/gsl_ieee_utils.h>
22 #include <gsl/gsl_errno.h>
23
24 /* This is a copy of fp-netbsd.c, modified for openbsd by Toby White
25    --- Brian Gough */
26
27 int
28 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
29 {
30   fp_except mode = 0;
31   fp_rnd    rnd  = 0;
32
33   switch (precision)
34     {
35     case GSL_IEEE_SINGLE_PRECISION:
36       GSL_ERROR ("OpenBSD only supports default precision rounding",
37                  GSL_EUNSUP);
38       break;
39     case GSL_IEEE_DOUBLE_PRECISION:
40       GSL_ERROR ("OpenBSD only supports default precision rounding",
41                  GSL_EUNSUP);
42       break;
43     case GSL_IEEE_EXTENDED_PRECISION:
44       GSL_ERROR ("OpenBSD only supports default precision rounding",
45                  GSL_EUNSUP);
46       break;
47     }
48
49   switch (rounding)
50     {
51     case GSL_IEEE_ROUND_TO_NEAREST:
52       rnd = FP_RN;
53       fpsetround (rnd);
54       break;
55     case GSL_IEEE_ROUND_DOWN:
56       rnd = FP_RM;
57       fpsetround (rnd);
58       break;
59     case GSL_IEEE_ROUND_UP:
60       rnd = FP_RP;
61       fpsetround (rnd);
62       break;
63     case GSL_IEEE_ROUND_TO_ZERO:
64       rnd = FP_RZ;
65       fpsetround (rnd);
66       break;
67     default:
68       rnd = FP_RN;
69       fpsetround (rnd);
70     }
71
72 /* Turn on all available exceptions apart from 'inexact'.
73    Denormalized operand exception not available on all platforms. */
74
75   mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL;
76 #ifdef FP_X_DNML
77   mode = mode | FP_X_DNML;
78 #endif
79
80   if (exception_mask & GSL_IEEE_MASK_INVALID)
81     mode &= ~ FP_X_INV;
82
83   if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
84     {
85 #ifdef FP_X_DNML
86       mode &= ~ FP_X_DNML;
87 #endif
88     }
89   else
90     {
91 #ifndef FP_X_DNML
92       GSL_ERROR ("OpenBSD does not support the denormalized operand exception on this platform. "
93                  "Use 'mask-denormalized' to work around this.",
94                  GSL_EUNSUP);
95 #endif
96     }
97
98   if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
99     mode &= ~ FP_X_DZ;
100
101   if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
102     mode &= ~ FP_X_OFL;
103
104   if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
105     mode &=  ~ FP_X_UFL;
106
107   if (exception_mask & GSL_IEEE_TRAP_INEXACT)
108     {
109       mode |= FP_X_IMP;
110     }
111   else
112     {
113       mode &= ~ FP_X_IMP;
114     }
115
116   fpsetmask (mode);
117
118   return GSL_SUCCESS;
119
120 }
121