add_fp_control.patch 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. ---
  2. ieee-utils/fp-win.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  3. ieee-utils/fp.c | 2 ++
  4. 2 files changed, 72 insertions(+)
  5. create mode 100644 ieee-utils/fp-win.c
  6. diff --git a/ieee-utils/fp-win.c b/ieee-utils/fp-win.c
  7. new file mode 100644
  8. index 0000000..e024eae
  9. --- /dev/null
  10. +++ b/ieee-utils/fp-win.c
  11. @@ -0,0 +1,70 @@
  12. +/* fp-win.c
  13. + *
  14. + * Author: Brian Gladman
  15. + *
  16. + * This program is free software; you can redistribute it and/or modify
  17. + * it under the terms of the GNU General Public License as published by
  18. + * the Free Software Foundation; either version 2 of the License, or (at
  19. + * your option) any later version.
  20. + *
  21. + * This program is distributed in the hope that it will be useful, but
  22. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  23. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. + * General Public License for more details.
  25. + *
  26. + * You should have received a copy of the GNU General Public License
  27. + * along with this program; if not, write to the Free Software
  28. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  29. + */
  30. +
  31. +#include <float.h>
  32. +
  33. +#include <config.h>
  34. +#include <gsl/gsl_ieee_utils.h>
  35. +#include <gsl/gsl_errno.h>
  36. +
  37. +const char *fp_env_string = "round-to-nearest,double-precision,mask-all";
  38. +
  39. +int
  40. +gsl_ieee_set_mode (int precision, int rounding, int exception_mask)
  41. +{
  42. + unsigned int old, mode = _DN_SAVE, mask = _MCW_DN | _MCW_RC | _MCW_EM;
  43. +
  44. + switch(precision)
  45. + {
  46. + case GSL_IEEE_SINGLE_PRECISION: mode |= _PC_24; break;
  47. + case GSL_IEEE_EXTENDED_PRECISION: mode |= _PC_64; break;
  48. + case GSL_IEEE_DOUBLE_PRECISION:
  49. + default: mode |= _PC_53;
  50. + }
  51. +#ifndef _M_AMD64
  52. + mask |= _MCW_PC;
  53. +#endif
  54. +
  55. + switch(rounding)
  56. + {
  57. + case GSL_IEEE_ROUND_DOWN: mode |= _RC_DOWN; break;
  58. + case GSL_IEEE_ROUND_UP: mode |= _RC_UP; break;
  59. + case GSL_IEEE_ROUND_TO_ZERO: mode |= _RC_CHOP; break;
  60. + case GSL_IEEE_ROUND_TO_NEAREST:
  61. + default: mode |= _RC_NEAR;
  62. + }
  63. +
  64. + if(exception_mask & GSL_IEEE_MASK_INVALID)
  65. + mode |= _EM_INVALID;
  66. + if(exception_mask & GSL_IEEE_MASK_DENORMALIZED)
  67. + mode |= _EM_DENORMAL;
  68. + if(exception_mask & GSL_IEEE_MASK_DIVISION_BY_ZERO)
  69. + mode |= _EM_ZERODIVIDE;
  70. + if(exception_mask & GSL_IEEE_MASK_OVERFLOW)
  71. + mode |= _EM_OVERFLOW;
  72. + if(exception_mask & GSL_IEEE_MASK_UNDERFLOW)
  73. + mode |= _EM_UNDERFLOW;
  74. + if(exception_mask & GSL_IEEE_TRAP_INEXACT)
  75. + mode &= ~_EM_INEXACT;
  76. + else
  77. + mode |= _EM_INEXACT;
  78. +
  79. + _controlfp_s( &old, mode, mask);
  80. + return GSL_SUCCESS;
  81. +}
  82. diff --git a/ieee-utils/fp.c b/ieee-utils/fp.c
  83. index 445a14f..b6ae5af 100644
  84. --- a/ieee-utils/fp.c
  85. +++ b/ieee-utils/fp.c
  86. @@ -45,6 +45,8 @@
  87. #endif
  88. #elif HAVE_DECL_FEENABLEEXCEPT || HAVE_DECL_FESETTRAPENABLE
  89. #include "fp-gnuc99.c"
  90. +#elif _MSC_VER
  91. +#include "fp-win.c"
  92. #else
  93. #include "fp-unknown.c"
  94. #endif
  95. --