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
16
17 #ifndef Foundation_FPEnvironment_C99_INCLUDED
18 #define Foundation_FPEnvironment_C99_INCLUDED
19
20
21 #include "Poco/Foundation.h"
22 #include <fenv.h>
23 #include <cmath>
24
25
26 namespace Poco {
27
28
29 class FPEnvironmentImpl
30 {
31 protected:
32 enum RoundingModeImpl
33 {
34 FP_ROUND_DOWNWARD_IMPL = FE_DOWNWARD,
35 FP_ROUND_UPWARD_IMPL = FE_UPWARD,
36 FP_ROUND_TONEAREST_IMPL = FE_TONEAREST,
37 FP_ROUND_TOWARDZERO_IMPL = FE_TOWARDZERO
38 };
39 enum FlagImpl
40 {
41 FP_DIVIDE_BY_ZERO_IMPL = FE_DIVBYZERO,
42 FP_INEXACT_IMPL = FE_INEXACT,
43 FP_OVERFLOW_IMPL = FE_OVERFLOW,
44 FP_UNDERFLOW_IMPL = FE_UNDERFLOW,
45 FP_INVALID_IMPL = FE_INVALID
46 };
47 FPEnvironmentImpl();
48 FPEnvironmentImpl(const FPEnvironmentImpl& env);
49 ~FPEnvironmentImpl();
50 FPEnvironmentImpl& operator = (const FPEnvironmentImpl& env);
51 void keepCurrentImpl();
52 static void clearFlagsImpl();
53 static bool isFlagImpl(FlagImpl flag);
54 static void setRoundingModeImpl(RoundingModeImpl mode);
55 static RoundingModeImpl getRoundingModeImpl();
56 static bool isInfiniteImpl(float value);
57 static bool isInfiniteImpl(double value);
58 static bool isInfiniteImpl(long double value);
59 static bool isNaNImpl(float value);
60 static bool isNaNImpl(double value);
61 static bool isNaNImpl(long double value);
62 static float copySignImpl(float target, float source);
63 static double copySignImpl(double target, double source);
64 static long double copySignImpl(long double target, long double source);
65
66 private:
67 fenv_t _env;
68 };
69
70
71 //
72 // inlines
73 //
isInfiniteImpl(float value)74 inline bool FPEnvironmentImpl::isInfiniteImpl(float value)
75 {
76 return std::isinf(value) != 0;
77 }
78
79
isInfiniteImpl(double value)80 inline bool FPEnvironmentImpl::isInfiniteImpl(double value)
81 {
82 return std::isinf(value) != 0;
83 }
84
85
isInfiniteImpl(long double value)86 inline bool FPEnvironmentImpl::isInfiniteImpl(long double value)
87 {
88 return std::isinf((double) value) != 0;
89 }
90
91
isNaNImpl(float value)92 inline bool FPEnvironmentImpl::isNaNImpl(float value)
93 {
94 return std::isnan(value) != 0;
95 }
96
97
isNaNImpl(double value)98 inline bool FPEnvironmentImpl::isNaNImpl(double value)
99 {
100 return std::isnan(value) != 0;
101 }
102
103
isNaNImpl(long double value)104 inline bool FPEnvironmentImpl::isNaNImpl(long double value)
105 {
106 return std::isnan((double) value) != 0;
107 }
108
109
copySignImpl(float target,float source)110 inline float FPEnvironmentImpl::copySignImpl(float target, float source)
111 {
112 return copysignf(target, source);
113 }
114
115
copySignImpl(double target,double source)116 inline double FPEnvironmentImpl::copySignImpl(double target, double source)
117 {
118 return copysign(target, source);
119 }
120
121
122 } // namespace Poco
123
124
125 #endif // Foundation_FPEnvironment_C99_INCLUDED
126