Coverage Report

Created: 2026-03-01 07:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poco/Foundation/include/Poco/FPEnvironment.h
Line
Count
Source
1
//
2
// FPEnvironment.h
3
//
4
// Library: Foundation
5
// Package: Core
6
// Module:  FPEnvironment
7
//
8
// Definitions of class 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
16
17
#ifndef Foundation_FPEnvironment_INCLUDED
18
#define Foundation_FPEnvironment_INCLUDED
19
20
21
#include "Poco/Foundation.h"
22
23
24
#if defined(POCO_NO_FPENVIRONMENT)
25
#include "Poco/FPEnvironment_DUMMY.h"
26
#elif defined(__osf__)
27
#include "Poco/FPEnvironment_DEC.h"
28
#elif defined(sun) || defined(__sun)
29
#include "Poco/FPEnvironment_SUN.h"
30
#elif defined(__QNX__)
31
#include "Poco/FPEnvironment_QNX.h"
32
#elif defined(POCO_OS_FAMILY_UNIX)
33
#include "Poco/FPEnvironment_C99.h"
34
#elif defined(POCO_OS_FAMILY_WINDOWS)
35
#include "Poco/FPEnvironment_WIN32.h"
36
#else
37
#include "Poco/FPEnvironment_DUMMY.h"
38
#endif
39
40
41
namespace Poco {
42
43
44
class Foundation_API FPEnvironment: private FPEnvironmentImpl
45
  /// Instances of this class can be used to save
46
  /// and later restore the current floating
47
  /// point environment (consisting of rounding
48
  /// mode and floating-point flags).
49
  /// The class also provides various static
50
  /// methods to query certain properties
51
  /// of a floating-point number.
52
{
53
public:
54
  enum RoundingMode
55
  {
56
    FP_ROUND_DOWNWARD   = FP_ROUND_DOWNWARD_IMPL,
57
    FP_ROUND_UPWARD     = FP_ROUND_UPWARD_IMPL,
58
    FP_ROUND_TONEAREST  = FP_ROUND_TONEAREST_IMPL,
59
    FP_ROUND_TOWARDZERO = FP_ROUND_TOWARDZERO_IMPL
60
  };
61
62
  enum Flag
63
  {
64
    FP_DIVIDE_BY_ZERO = FP_DIVIDE_BY_ZERO_IMPL,
65
    FP_INEXACT        = FP_INEXACT_IMPL,
66
    FP_OVERFLOW       = FP_OVERFLOW_IMPL,
67
    FP_UNDERFLOW      = FP_UNDERFLOW_IMPL,
68
    FP_INVALID        = FP_INVALID_IMPL
69
  };
70
71
  FPEnvironment();
72
    /// Standard constructor.
73
    /// Remembers the current environment.
74
75
  FPEnvironment(RoundingMode mode);
76
    /// Remembers the current environment and
77
    /// sets the given rounding mode.
78
79
  FPEnvironment(const FPEnvironment& env);
80
    /// Copy constructor.
81
82
  ~FPEnvironment();
83
    /// Restores the previous environment (unless
84
    /// keepCurrent() has been called previously)
85
86
  FPEnvironment& operator = (const FPEnvironment& env);
87
    /// Assignment operator
88
89
  void keepCurrent();
90
    /// Keep the current environment even after
91
    /// destroying the FPEnvironment object.
92
93
  static void clearFlags();
94
    /// Resets all flags.
95
96
  static bool isFlag(Flag flag);
97
    /// Returns true iff the given flag is set.
98
99
  static void setRoundingMode(RoundingMode mode);
100
    /// Sets the rounding mode.
101
102
  static RoundingMode getRoundingMode();
103
    /// Returns the current rounding mode.
104
105
  static bool isInfinite(float value);
106
  static bool isInfinite(double value);
107
  static bool isInfinite(long double value);
108
    /// Returns true iff the given number is infinite.
109
110
  static bool isNaN(float value);
111
  static bool isNaN(double value);
112
  static bool isNaN(long double value);
113
    /// Returns true iff the given number is NaN.
114
115
  static float copySign(float target, float source);
116
  static double copySign(double target, double source);
117
  static long double copySign(long double target, long double source);
118
    /// Copies the sign from source to target.
119
};
120
121
122
//
123
// For convenience, we provide a shorter name for
124
// the FPEnvironment class.
125
//
126
using FPE = FPEnvironment;
127
128
//
129
// inline's
130
//
131
inline bool FPEnvironment::isFlag(Flag flag)
132
0
{
133
0
  return isFlagImpl(FlagImpl(flag));
134
0
}
135
136
137
inline void FPEnvironment::setRoundingMode(RoundingMode mode)
138
0
{
139
0
  setRoundingModeImpl(RoundingModeImpl(mode));
140
0
}
141
142
143
inline FPEnvironment::RoundingMode FPEnvironment::getRoundingMode()
144
0
{
145
0
  return RoundingMode(getRoundingModeImpl());
146
0
}
147
148
149
inline bool FPEnvironment::isInfinite(float value)
150
0
{
151
0
  return isInfiniteImpl(value);
152
0
}
153
154
155
inline bool FPEnvironment::isInfinite(double value)
156
669k
{
157
669k
  return isInfiniteImpl(value);
158
669k
}
159
160
161
inline bool FPEnvironment::isInfinite(long double value)
162
0
{
163
0
  return isInfiniteImpl(value);
164
0
}
165
166
167
inline bool FPEnvironment::isNaN(float value)
168
0
{
169
0
  return isNaNImpl(value);
170
0
}
171
172
173
inline bool FPEnvironment::isNaN(double value)
174
668k
{
175
668k
  return isNaNImpl(value);
176
668k
}
177
178
179
inline bool FPEnvironment::isNaN(long double value)
180
0
{
181
0
  return isNaNImpl(value);
182
0
}
183
184
185
inline float FPEnvironment::copySign(float target, float source)
186
0
{
187
0
  return copySignImpl(target, source);
188
0
}
189
190
191
inline double FPEnvironment::copySign(double target, double source)
192
0
{
193
0
  return copySignImpl(target, source);
194
0
}
195
196
197
inline long double FPEnvironment::copySign(long double target, long double source)
198
0
{
199
0
  return copySignImpl(target, source);
200
0
}
201
202
203
} // namespace Poco
204
205
206
#endif // Foundation_FPEnvironment_INCLUDED