FPEnvironment_C99.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // FPEnvironment_C99.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/FPEnvironment_C99.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Core
  8. // Module: FPEnvironment
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/FPEnvironment_C99.h"
  16. namespace Poco {
  17. FPEnvironmentImpl::FPEnvironmentImpl()
  18. {
  19. fegetenv(&_env);
  20. }
  21. FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
  22. {
  23. _env = env._env;
  24. }
  25. FPEnvironmentImpl::~FPEnvironmentImpl()
  26. {
  27. fesetenv(&_env);
  28. }
  29. FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
  30. {
  31. _env = env._env;
  32. return *this;
  33. }
  34. void FPEnvironmentImpl::keepCurrentImpl()
  35. {
  36. fegetenv(&_env);
  37. }
  38. void FPEnvironmentImpl::clearFlagsImpl()
  39. {
  40. feclearexcept(FE_ALL_EXCEPT);
  41. }
  42. bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
  43. {
  44. return fetestexcept(flag) != 0;
  45. }
  46. void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
  47. {
  48. fesetround(mode);
  49. }
  50. FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
  51. {
  52. return (RoundingModeImpl) fegetround();
  53. }
  54. long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
  55. {
  56. return (source >= 0 && target >= 0) || (source < 0 && target < 0) ? target : -target;
  57. }
  58. } // namespace Poco