FPEnvironment_C99.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // FPEnvironment_C99.h
  3. //
  4. // Library: Foundation
  5. // Package: Core
  6. // Module: FPEnvironment
  7. //
  8. // Definitions of class FPEnvironmentImpl for C99.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_FPEnvironment_C99_INCLUDED
  16. #define Foundation_FPEnvironment_C99_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include <fenv.h>
  19. #include <cmath>
  20. namespace Poco {
  21. class FPEnvironmentImpl
  22. {
  23. protected:
  24. enum RoundingModeImpl
  25. {
  26. FP_ROUND_DOWNWARD_IMPL = FE_DOWNWARD,
  27. FP_ROUND_UPWARD_IMPL = FE_UPWARD,
  28. FP_ROUND_TONEAREST_IMPL = FE_TONEAREST,
  29. FP_ROUND_TOWARDZERO_IMPL = FE_TOWARDZERO
  30. };
  31. enum FlagImpl
  32. {
  33. FP_DIVIDE_BY_ZERO_IMPL = FE_DIVBYZERO,
  34. FP_INEXACT_IMPL = FE_INEXACT,
  35. FP_OVERFLOW_IMPL = FE_OVERFLOW,
  36. FP_UNDERFLOW_IMPL = FE_UNDERFLOW,
  37. FP_INVALID_IMPL = FE_INVALID
  38. };
  39. FPEnvironmentImpl();
  40. FPEnvironmentImpl(const FPEnvironmentImpl& env);
  41. ~FPEnvironmentImpl();
  42. FPEnvironmentImpl& operator = (const FPEnvironmentImpl& env);
  43. void keepCurrentImpl();
  44. static void clearFlagsImpl();
  45. static bool isFlagImpl(FlagImpl flag);
  46. static void setRoundingModeImpl(RoundingModeImpl mode);
  47. static RoundingModeImpl getRoundingModeImpl();
  48. static bool isInfiniteImpl(float value);
  49. static bool isInfiniteImpl(double value);
  50. static bool isInfiniteImpl(long double value);
  51. static bool isNaNImpl(float value);
  52. static bool isNaNImpl(double value);
  53. static bool isNaNImpl(long double value);
  54. static float copySignImpl(float target, float source);
  55. static double copySignImpl(double target, double source);
  56. static long double copySignImpl(long double target, long double source);
  57. private:
  58. fenv_t _env;
  59. };
  60. //
  61. // inlines
  62. //
  63. inline bool FPEnvironmentImpl::isInfiniteImpl(float value)
  64. {
  65. return std::isinf(value) != 0;
  66. }
  67. inline bool FPEnvironmentImpl::isInfiniteImpl(double value)
  68. {
  69. return std::isinf(value) != 0;
  70. }
  71. inline bool FPEnvironmentImpl::isInfiniteImpl(long double value)
  72. {
  73. return std::isinf((double) value) != 0;
  74. }
  75. inline bool FPEnvironmentImpl::isNaNImpl(float value)
  76. {
  77. return std::isnan(value) != 0;
  78. }
  79. inline bool FPEnvironmentImpl::isNaNImpl(double value)
  80. {
  81. return std::isnan(value) != 0;
  82. }
  83. inline bool FPEnvironmentImpl::isNaNImpl(long double value)
  84. {
  85. return std::isnan((double) value) != 0;
  86. }
  87. inline float FPEnvironmentImpl::copySignImpl(float target, float source)
  88. {
  89. return copysignf(target, source);
  90. }
  91. inline double FPEnvironmentImpl::copySignImpl(double target, double source)
  92. {
  93. return copysign(target, source);
  94. }
  95. } // namespace Poco
  96. #endif // Foundation_FPEnvironment_C99_INCLUDED