| 1 |
/* ieee-utils/gsl_ieee_utils.h |
| 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 |
#ifndef __GSL_IEEE_UTILS_H__ |
| 21 |
#define __GSL_IEEE_UTILS_H__ |
| 22 |
#include <stdio.h> |
| 23 |
|
| 24 |
#undef __BEGIN_DECLS |
| 25 |
#undef __END_DECLS |
| 26 |
#ifdef __cplusplus |
| 27 |
# define __BEGIN_DECLS extern "C" { |
| 28 |
# define __END_DECLS } |
| 29 |
#else |
| 30 |
# define __BEGIN_DECLS /* empty */ |
| 31 |
# define __END_DECLS /* empty */ |
| 32 |
#endif |
| 33 |
|
| 34 |
__BEGIN_DECLS |
| 35 |
|
| 36 |
enum { |
| 37 |
GSL_IEEE_TYPE_NAN = 1, |
| 38 |
GSL_IEEE_TYPE_INF = 2, |
| 39 |
GSL_IEEE_TYPE_NORMAL = 3, |
| 40 |
GSL_IEEE_TYPE_DENORMAL = 4, |
| 41 |
GSL_IEEE_TYPE_ZERO = 5 |
| 42 |
} ; |
| 43 |
|
| 44 |
typedef struct { |
| 45 |
int sign ; |
| 46 |
char mantissa[24] ; /* Actual bits are 0..22, element 23 is \0 */ |
| 47 |
int exponent ; |
| 48 |
int type ; |
| 49 |
} gsl_ieee_float_rep ; |
| 50 |
|
| 51 |
typedef struct { |
| 52 |
int sign ; |
| 53 |
char mantissa[53] ; /* Actual bits are 0..51, element 52 is \0 */ |
| 54 |
int exponent ; |
| 55 |
int type ; |
| 56 |
} gsl_ieee_double_rep ; |
| 57 |
|
| 58 |
|
| 59 |
void gsl_ieee_printf_float (const float * x) ; |
| 60 |
void gsl_ieee_printf_double (const double * x) ; |
| 61 |
|
| 62 |
void gsl_ieee_fprintf_float (FILE * stream, const float * x) ; |
| 63 |
void gsl_ieee_fprintf_double (FILE * stream, const double * x) ; |
| 64 |
|
| 65 |
void gsl_ieee_float_to_rep (const float * x, gsl_ieee_float_rep * r) ; |
| 66 |
void gsl_ieee_double_to_rep (const double * x, gsl_ieee_double_rep * r) ; |
| 67 |
|
| 68 |
enum { |
| 69 |
GSL_IEEE_SINGLE_PRECISION = 1, |
| 70 |
GSL_IEEE_DOUBLE_PRECISION = 2, |
| 71 |
GSL_IEEE_EXTENDED_PRECISION = 3 |
| 72 |
} ; |
| 73 |
|
| 74 |
enum { |
| 75 |
GSL_IEEE_ROUND_TO_NEAREST = 1, |
| 76 |
GSL_IEEE_ROUND_DOWN = 2, |
| 77 |
GSL_IEEE_ROUND_UP = 3, |
| 78 |
GSL_IEEE_ROUND_TO_ZERO = 4 |
| 79 |
} ; |
| 80 |
|
| 81 |
enum { |
| 82 |
GSL_IEEE_MASK_INVALID = 1, |
| 83 |
GSL_IEEE_MASK_DENORMALIZED = 2, |
| 84 |
GSL_IEEE_MASK_DIVISION_BY_ZERO = 4, |
| 85 |
GSL_IEEE_MASK_OVERFLOW = 8, |
| 86 |
GSL_IEEE_MASK_UNDERFLOW = 16, |
| 87 |
GSL_IEEE_MASK_ALL = 31, |
| 88 |
GSL_IEEE_TRAP_INEXACT = 32 |
| 89 |
} ; |
| 90 |
|
| 91 |
void gsl_ieee_env_setup (void) ; |
| 92 |
int gsl_ieee_read_mode_string (const char * description, int * precision, |
| 93 |
int * rounding, int * exception_mask) ; |
| 94 |
int gsl_ieee_set_mode (int precision, int rounding, int exception_mask) ; |
| 95 |
|
| 96 |
__END_DECLS |
| 97 |
|
| 98 |
#endif /* __GSL_IEEE_UTILS_H__ */ |
| 99 |
|