gsl_ieee-utils__fp-hpux.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* ieee-utils/fp-hpux.c
  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. #include <math.h>
  20. #include <stdio.h>
  21. #include "gsl_ieee_utils.h"
  22. #include "gsl_errno.h"
  23. int
  24. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  25. {
  26. fp_except mode = 0 ;
  27. fp_rnd rnd = 0 ;
  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. rnd = FP_RN ;
  47. fpsetround (rnd) ;
  48. break ;
  49. case GSL_IEEE_ROUND_DOWN:
  50. rnd = FP_RM ;
  51. fpsetround (rnd) ;
  52. break ;
  53. case GSL_IEEE_ROUND_UP:
  54. rnd = FP_RP ;
  55. fpsetround (rnd) ;
  56. break ;
  57. case GSL_IEEE_ROUND_TO_ZERO:
  58. rnd = FP_RZ ;
  59. fpsetround (rnd) ;
  60. break ;
  61. default:
  62. rnd = FP_RN ;
  63. fpsetround (rnd) ;
  64. }
  65. /* Turn on all the exceptions apart from 'inexact' */
  66. mode = FP_X_INV | FP_X_DZ | FP_X_OFL | FP_X_UFL ;
  67. if (exception_mask & GSL_IEEE_MASK_INVALID)
  68. mode &= ~ FP_X_INV ;
  69. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  70. {
  71. /* do nothing */
  72. }
  73. else
  74. {
  75. GSL_ERROR ("HP-UX does not support the denormalized operand exception. "
  76. "Use 'mask-denormalized' to work around this.",
  77. GSL_EUNSUP) ;
  78. }
  79. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  80. mode &= ~ FP_X_DZ ;
  81. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  82. mode &= ~ FP_X_OFL ;
  83. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  84. mode &= ~ FP_X_UFL ;
  85. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  86. {
  87. mode |= FP_X_IMP ;
  88. }
  89. else
  90. {
  91. mode &= ~ FP_X_IMP ;
  92. }
  93. fpsetmask (mode) ;
  94. return GSL_SUCCESS ;
  95. }