Debian Codegraph @

external/gsl/gsl_ieee-utils__fp-hpux.c

raw symbols SCIP
1 /* ieee-utils/fp-hpux.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 <stdio.h>
22 #include "gsl_ieee_utils.h"
23 #include "gsl_errno.h"
24
25 int
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 ("HPUX PA-RISC only supports default precision rounding",
35 GSL_EUNSUP) ;
36 break ;
37 case GSL_IEEE_DOUBLE_PRECISION:
38 GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
39 GSL_EUNSUP) ;
40 break ;
41 case GSL_IEEE_EXTENDED_PRECISION:
42 GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
43 GSL_EUNSUP) ;
44 break ;
45 }
46
47
48 switch (rounding)
49 {
50 case GSL_IEEE_ROUND_TO_NEAREST:
51 rnd = FP_RN ;
52 fpsetround (rnd) ;
53 break ;
54 case GSL_IEEE_ROUND_DOWN:
55 rnd = FP_RM ;
56 fpsetround (rnd) ;
57 break ;
58 case GSL_IEEE_ROUND_UP:
59 rnd = FP_RP ;
60 fpsetround (rnd) ;
61 break ;
62 case GSL_IEEE_ROUND_TO_ZERO:
63 rnd = FP_RZ ;
64 fpsetround (rnd) ;
65 break ;
66 default:
67 rnd = FP_RN ;
68 fpsetround (rnd) ;
69 }
70
71 /* Turn on all the exceptions apart from 'inexact' */
72
73 mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
74
75 if (exception_mask & GSL_IEEE_MASK_INVALID)
76 mode &= ~ FP_X_INV ;
77
78 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
79 {
80 /* do nothing */
81 }
82 else
83 {
84 GSL_ERROR ("HP-UX does not support the denormalized operand exception. "
85 "Use 'mask-denormalized' to work around this.",
86 GSL_EUNSUP) ;
87 }
88
89 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
90 mode &= ~ FP_X_DZ ;
91
92 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
93 mode &= ~ FP_X_OFL ;
94
95 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
96 mode &= ~ FP_X_UFL ;
97
98 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
99 {
100 mode |= FP_X_IMP ;
101 }
102 else
103 {
104 mode &= ~ FP_X_IMP ;
105 }
106
107 fpsetmask (mode) ;
108
109 return GSL_SUCCESS ;
110 }