gsl_ieee-utils__fp-sunos4.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* ieee-utils/fp-sunos4.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 <sys/ieeefp.h>
  20. #include <floatingpoint.h>
  21. #include <signal.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. char * out ;
  28. switch (precision)
  29. {
  30. case GSL_IEEE_SINGLE_PRECISION:
  31. ieee_flags ("set", "precision", "single", out) ;
  32. break ;
  33. case GSL_IEEE_DOUBLE_PRECISION:
  34. ieee_flags ("set", "precision", "double", out) ;
  35. break ;
  36. case GSL_IEEE_EXTENDED_PRECISION:
  37. ieee_flags ("set", "precision", "extended", out) ;
  38. break ;
  39. default:
  40. ieee_flags ("set", "precision", "extended", out) ;
  41. }
  42. switch (rounding)
  43. {
  44. case GSL_IEEE_ROUND_TO_NEAREST:
  45. ieee_flags ("set", "direction", "nearest", out) ;
  46. break ;
  47. case GSL_IEEE_ROUND_DOWN:
  48. ieee_flags ("set", "direction", "negative", out) ;
  49. break ;
  50. case GSL_IEEE_ROUND_UP:
  51. ieee_flags ("set", "direction", "positive", out) ;
  52. break ;
  53. case GSL_IEEE_ROUND_TO_ZERO:
  54. ieee_flags ("set", "direction", "tozero", out) ;
  55. break ;
  56. default:
  57. ieee_flags ("set", "direction", "nearest", out) ;
  58. }
  59. if (exception_mask & GSL_IEEE_MASK_INVALID)
  60. {
  61. ieee_handler ("set", "invalid", SIGFPE_IGNORE) ;
  62. }
  63. else
  64. {
  65. ieee_handler ("set", "invalid", SIGFPE_ABORT) ;
  66. }
  67. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  68. {
  69. ieee_handler ("set", "denormalized", SIGFPE_IGNORE) ;
  70. }
  71. else
  72. {
  73. GSL_ERROR ("sunos4 does not support the denormalized operand exception. "
  74. "Use 'mask-denormalized' to work around this.",
  75. GSL_EUNSUP) ;
  76. }
  77. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  78. {
  79. ieee_handler ("set", "division", SIGFPE_IGNORE) ;
  80. }
  81. else
  82. {
  83. ieee_handler ("set", "division", SIGFPE_ABORT) ;
  84. }
  85. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  86. {
  87. ieee_handler ("set", "overflow", SIGFPE_IGNORE) ;
  88. }
  89. else
  90. {
  91. ieee_handler ("set", "overflow", SIGFPE_ABORT) ;
  92. }
  93. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  94. {
  95. ieee_handler ("set", "underflow", SIGFPE_IGNORE) ;
  96. }
  97. else
  98. {
  99. ieee_handler ("set", "underflow", SIGFPE_ABORT) ;
  100. }
  101. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  102. {
  103. ieee_handler ("set", "inexact", SIGFPE_ABORT) ;
  104. }
  105. else
  106. {
  107. ieee_handler ("set", "inexact", SIGFPE_IGNORE) ;
  108. }
  109. return GSL_SUCCESS ;
  110. }