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