gsl_ieee-utils__fp-os2emx.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* ieee-utils/fp-os2.c
  2. *
  3. * Copyright (C) 2001 Henry Sobotka <sobotka@axess.com>
  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 <float.h>
  20. #include "gsl_ieee_utils.h"
  21. #include "gsl_errno.h"
  22. int
  23. gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  24. {
  25. unsigned mode = 0;
  26. switch (precision)
  27. {
  28. case GSL_IEEE_SINGLE_PRECISION:
  29. _control87(PC_24, MCW_PC);
  30. break ;
  31. case GSL_IEEE_DOUBLE_PRECISION:
  32. _control87(PC_53, MCW_PC);
  33. break ;
  34. case GSL_IEEE_EXTENDED_PRECISION:
  35. _control87(PC_64, MCW_PC);
  36. break ;
  37. }
  38. switch (rounding)
  39. {
  40. case GSL_IEEE_ROUND_TO_NEAREST:
  41. _control87(RC_NEAR, MCW_RC);
  42. break ;
  43. case GSL_IEEE_ROUND_DOWN:
  44. _control87(RC_DOWN, MCW_RC);
  45. break ;
  46. case GSL_IEEE_ROUND_UP:
  47. _control87(RC_UP, MCW_RC);
  48. break ;
  49. case GSL_IEEE_ROUND_TO_ZERO:
  50. _control87(RC_CHOP, MCW_RC);
  51. break ;
  52. default:
  53. _control87(RC_NEAR, MCW_RC);
  54. }
  55. /* Turn on all the exceptions apart from 'inexact' */
  56. mode = EM_INVALID | EM_DENORMAL | EM_ZERODIVIDE | EM_OVERFLOW | EM_UNDERFLOW;
  57. if (exception_mask & GSL_IEEE_MASK_INVALID)
  58. mode &= ~ EM_INVALID;
  59. if (exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  60. mode &= ~ EM_DENORMAL;
  61. if (exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  62. mode &= ~ EM_ZERODIVIDE;
  63. if (exception_mask & GSL_IEEE_MASK_OVERFLOW)
  64. mode &= ~ EM_OVERFLOW;
  65. if (exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  66. mode &= ~ EM_UNDERFLOW;
  67. if (exception_mask & GSL_IEEE_TRAP_INEXACT)
  68. {
  69. mode |= EM_INEXACT;
  70. }
  71. else
  72. {
  73. mode &= ~ EM_INEXACT;
  74. }
  75. _control87(mode, MCW_EM);
  76. return GSL_SUCCESS ;
  77. }