3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
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.
22 #include <gsl/gsl_ieee_utils.h>
23 #include <gsl/gsl_errno.h>
26 gsl_ieee_env_setup (void)
28 const char * p = getenv("GSL_IEEE_MODE") ;
30 int precision = 0, rounding = 0, exception_mask = 0 ;
34 if (p == 0) /* GSL_IEEE_MODE environment variable is not set */
37 if (*p == '\0') /* GSL_IEEE_MODE environment variable is empty */
40 gsl_ieee_read_mode_string (p, &precision, &rounding, &exception_mask) ;
42 gsl_ieee_set_mode (precision, rounding, exception_mask) ;
44 fprintf(stderr, "GSL_IEEE_MODE=\"") ;
46 /* Print string with a preceeding comma if the list has already begun */
48 #define PRINTC(x) do {if(comma) fprintf(stderr,","); fprintf(stderr,x); comma++ ;} while(0)
52 case GSL_IEEE_SINGLE_PRECISION:
53 PRINTC("single-precision") ;
55 case GSL_IEEE_DOUBLE_PRECISION:
56 PRINTC("double-precision") ;
58 case GSL_IEEE_EXTENDED_PRECISION:
59 PRINTC("extended-precision") ;
65 case GSL_IEEE_ROUND_TO_NEAREST:
66 PRINTC("round-to-nearest") ;
68 case GSL_IEEE_ROUND_DOWN:
69 PRINTC("round-down") ;
71 case GSL_IEEE_ROUND_UP:
74 case GSL_IEEE_ROUND_TO_ZERO:
75 PRINTC("round-to-zero") ;
79 if ((exception_mask & GSL_IEEE_MASK_ALL) == GSL_IEEE_MASK_ALL)
83 else if ((exception_mask & GSL_IEEE_MASK_ALL) == 0)
85 PRINTC("trap-common") ;
89 if (exception_mask & GSL_IEEE_MASK_INVALID)
90 PRINTC("mask-invalid") ;
92 if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
93 PRINTC("mask-denormalized") ;
95 if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
96 PRINTC("mask-division-by-zero") ;
98 if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
99 PRINTC("mask-overflow") ;
101 if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
102 PRINTC("mask-underflow") ;
105 if (exception_mask & GSL_IEEE_TRAP_INEXACT)
106 PRINTC("trap-inexact") ;
108 fprintf(stderr,"\"\n") ;