gsl_ieee-utils__fp-hpux11.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* ieee-utils/fp-hpux11.c
  2. *
  3. * Copyright (C) 2001, 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. #include <math.h>
  20. #include <stdio.h>
  21. #include <fenv.h>
  22. #include "gsl_ieee_utils.h"
  23. #include "gsl_errno.h"
  24. int
  25. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  26. {
  27. int mode;
  28. switch (precision)
  29. {
  30. case GSL_IEEE_SINGLE_PRECISION:
  31. GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  32. GSL_EUNSUP) ;
  33. break ;
  34. case GSL_IEEE_DOUBLE_PRECISION:
  35. GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  36. GSL_EUNSUP) ;
  37. break ;
  38. case GSL_IEEE_EXTENDED_PRECISION:
  39. GSL_ERROR ("HPUX PA-RISC only supports default precision rounding",
  40. GSL_EUNSUP) ;
  41. break ;
  42. }
  43. switch (rounding)
  44. {
  45. case GSL_IEEE_ROUND_TO_NEAREST:
  46. fesetround (FE_TONEAREST) ;
  47. break ;
  48. case GSL_IEEE_ROUND_DOWN:
  49. fesetround (FE_DOWNWARD) ;
  50. break ;
  51. case GSL_IEEE_ROUND_UP:
  52. fesetround (FE_UPWARD) ;
  53. break ;
  54. case GSL_IEEE_ROUND_TO_ZERO:
  55. fesetround (FE_TOWARDZERO) ;
  56. break ;
  57. default:
  58. fesetround (FE_TONEAREST) ;
  59. }
  60. /* Turn on all the exceptions apart from 'inexact' */
  61. mode = FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW ;
  62. if (exception_mask & GSL_IEEE_MASK_INVALID)
  63. mode &= ~ FE_INVALID ;
  64. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  65. {
  66. /* do nothing */
  67. }
  68. else
  69. {
  70. GSL_ERROR ("HP-UX does not support the denormalized operand exception. "
  71. "Use 'mask-denormalized' to work around this.",
  72. GSL_EUNSUP) ;
  73. }
  74. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  75. mode &= ~ FE_DIVBYZERO ;
  76. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  77. mode &= ~ FE_OVERFLOW ;
  78. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  79. mode &= ~ FE_UNDERFLOW ;
  80. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  81. {
  82. mode |= FE_INEXACT ;
  83. }
  84. else
  85. {
  86. mode &= ~ FE_INEXACT ;
  87. }
  88. fesettrapenable (mode) ;
  89. return GSL_SUCCESS ;
  90. }