gsl_ieee_utils.h 2.7 KB

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