Debian Codegraph @

external/gsl/gsl_ieee-utils__fp-aix.c

raw symbols SCIP
1 /* ieee-utils/fp-aix.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000 Tim Mooney
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 <fptrap.h>
22 #include <float.h>
23 #include "gsl_ieee_utils.h"
24 #include "gsl_errno.h"
25
26 int
27 gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
28 {
29 fptrap_t mode = 0 ;
30 fprnd_t rnd = 0 ;
31
32 switch (precision)
33 {
34
35 /* I'm not positive about AIX only supporting default precision rounding,
36 * but this is the best assumption until it's proven otherwise. */
37
38 case GSL_IEEE_SINGLE_PRECISION:
39 GSL_ERROR ("AIX only supports default precision rounding",
40 GSL_EUNSUP) ;
41 break ;
42 case GSL_IEEE_DOUBLE_PRECISION:
43 GSL_ERROR ("AIX only supports default precision rounding",
44 GSL_EUNSUP) ;
45 break ;
46 case GSL_IEEE_EXTENDED_PRECISION:
47 GSL_ERROR ("AIX only supports default precision rounding",
48 GSL_EUNSUP) ;
49 break ;
50 }
51
52 switch (rounding)
53 {
54 case GSL_IEEE_ROUND_TO_NEAREST:
55 rnd = FP_RND_RN ;
56 fp_swap_rnd (rnd) ;
57 break ;
58 case GSL_IEEE_ROUND_DOWN:
59 rnd = FP_RND_RM ;
60 fp_swap_rnd (rnd) ;
61 break ;
62 case GSL_IEEE_ROUND_UP:
63 rnd = FP_RND_RP ;
64 fp_swap_rnd (rnd) ;
65 break ;
66 case GSL_IEEE_ROUND_TO_ZERO:
67 rnd = FP_RND_RZ ;
68 fp_swap_rnd (rnd) ;
69 break ;
70 default:
71 rnd = FP_RND_RN ;
72 fp_swap_rnd (rnd) ;
73 }
74
75 /* Turn on all the exceptions apart from 'inexact' */
76
77 mode = TRP_INVALID | TRP_DIV_BY_ZERO | TRP_OVERFLOW | TRP_UNDERFLOW ;
78
79 if (exception_mask & GSL_IEEE_MASK_INVALID)
80 mode &= ~ TRP_INVALID ;
81
82 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
83 {
84 /* do nothing */
85 }
86 else
87 {
88 GSL_ERROR ("AIX does not support the denormalized operand exception. "
89 "Use 'mask-denormalized' to work around this.",
90 GSL_EUNSUP) ;
91 }
92
93 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
94 mode &= ~ TRP_DIV_BY_ZERO ;
95
96 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
97 mode &= ~ TRP_OVERFLOW ;
98
99 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
100 mode &= ~ TRP_UNDERFLOW ;
101
102 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
103 {
104 mode |= TRP_INEXACT ;
105 }
106 else
107 {
108 mode &= ~ TRP_INEXACT ;
109 }
110
111 /* AIX appears to require two steps -- first enable floating point traps
112 * in general... */
113 fp_trap(FP_TRAP_SYNC);
114
115 /* next, enable the traps we're interested in */
116 fp_enable(mode);
117
118 return GSL_SUCCESS ;
119
120 }