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.
23 #include <gsl/gsl_ieee_utils.h>
25 /* A table of sign characters, 0=positive, 1=negative. We print a space
26 instead of a unary + sign for compatibility with bc */
28 static char signs[2]={' ','-'} ;
31 gsl_ieee_fprintf_float (FILE * stream, const float * x) {
32 gsl_ieee_float_rep r ;
33 gsl_ieee_float_to_rep(x, &r) ;
37 case GSL_IEEE_TYPE_NAN:
38 fprintf(stream, "NaN") ;
40 case GSL_IEEE_TYPE_INF:
41 fprintf(stream, "%cInf", signs[r.sign]) ;
43 case GSL_IEEE_TYPE_NORMAL:
44 fprintf(stream, "%c1.%s*2^%d", signs[r.sign], r.mantissa, r.exponent) ;
46 case GSL_IEEE_TYPE_DENORMAL:
47 fprintf(stream, "%c0.%s*2^%d", signs[r.sign], r.mantissa, r.exponent + 1) ;
49 case GSL_IEEE_TYPE_ZERO:
50 fprintf(stream, "%c0", signs[r.sign]) ;
53 fprintf(stream, "[non-standard IEEE float]") ;
58 gsl_ieee_printf_float (const float * x)
60 gsl_ieee_fprintf_float (stdout,x);
64 gsl_ieee_fprintf_double (FILE * stream, const double * x) {
65 gsl_ieee_double_rep r ;
66 gsl_ieee_double_to_rep (x, &r) ;
70 case GSL_IEEE_TYPE_NAN:
71 fprintf(stream, "NaN") ;
73 case GSL_IEEE_TYPE_INF:
74 fprintf(stream, "%cInf", signs[r.sign]) ;
76 case GSL_IEEE_TYPE_NORMAL:
77 fprintf(stream, "%c1.%s*2^%d", signs[r.sign], r.mantissa, r.exponent) ;
79 case GSL_IEEE_TYPE_DENORMAL:
80 fprintf(stream, "%c0.%s*2^%d", signs[r.sign], r.mantissa, r.exponent + 1) ;
82 case GSL_IEEE_TYPE_ZERO:
83 fprintf(stream, "%c0", signs[r.sign]) ;
86 fprintf(stream, "[non-standard IEEE double]") ;
91 gsl_ieee_printf_double (const double * x)
93 gsl_ieee_fprintf_double (stdout,x);