root / Community_Core_Vision / libs / poco / include / Poco / FPEnvironment_WIN32.h @ 11

View | Annotate | Download (4.1 KB)

1 11 amit
//
2 11 amit
// FPEnvironment_WIN32.h
3 11 amit
//
4 11 amit
// $Id: //poco/1.3/Foundation/include/Poco/FPEnvironment_WIN32.h#1 $
5 11 amit
//
6 11 amit
// Library: Foundation
7 11 amit
// Package: Core
8 11 amit
// Module:  FPEnvironment
9 11 amit
//
10 11 amit
// Definitions of class FPEnvironmentImpl for WIN32.
11 11 amit
//
12 11 amit
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
13 11 amit
// and Contributors.
14 11 amit
//
15 11 amit
// Permission is hereby granted, free of charge, to any person or organization
16 11 amit
// obtaining a copy of the software and accompanying documentation covered by
17 11 amit
// this license (the "Software") to use, reproduce, display, distribute,
18 11 amit
// execute, and transmit the Software, and to prepare derivative works of the
19 11 amit
// Software, and to permit third-parties to whom the Software is furnished to
20 11 amit
// do so, all subject to the following:
21 11 amit
//
22 11 amit
// The copyright notices in the Software and this entire statement, including
23 11 amit
// the above license grant, this restriction and the following disclaimer,
24 11 amit
// must be included in all copies of the Software, in whole or in part, and
25 11 amit
// all derivative works of the Software, unless such copies or derivative
26 11 amit
// works are solely in the form of machine-executable object code generated by
27 11 amit
// a source language processor.
28 11 amit
//
29 11 amit
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 11 amit
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 11 amit
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32 11 amit
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33 11 amit
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34 11 amit
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35 11 amit
// DEALINGS IN THE SOFTWARE.
36 11 amit
//
37 11 amit
38 11 amit
39 11 amit
#ifndef Foundation_FPEnvironment_WIN32_INCLUDED
40 11 amit
#define Foundation_FPEnvironment_WIN32_INCLUDED
41 11 amit
42 11 amit
43 11 amit
#include "Poco/Foundation.h"
44 11 amit
#include <float.h>
45 11 amit
#include <math.h>
46 11 amit
47 11 amit
48 11 amit
namespace Poco {
49 11 amit
50 11 amit
51 11 amit
class Foundation_API FPEnvironmentImpl
52 11 amit
{
53 11 amit
protected:
54 11 amit
        enum RoundingModeImpl
55 11 amit
        {
56 11 amit
                FP_ROUND_DOWNWARD_IMPL   = RC_DOWN,
57 11 amit
                FP_ROUND_UPWARD_IMPL     = RC_UP,
58 11 amit
                FP_ROUND_TONEAREST_IMPL  = RC_NEAR,
59 11 amit
                FP_ROUND_TOWARDZERO_IMPL = RC_CHOP
60 11 amit
        };
61 11 amit
        enum FlagImpl
62 11 amit
        {
63 11 amit
                FP_DIVIDE_BY_ZERO_IMPL = SW_ZERODIVIDE,
64 11 amit
                FP_INEXACT_IMPL        = SW_INEXACT,
65 11 amit
                FP_OVERFLOW_IMPL       = SW_OVERFLOW,
66 11 amit
                FP_UNDERFLOW_IMPL      = SW_UNDERFLOW,
67 11 amit
                FP_INVALID_IMPL        = SW_INVALID
68 11 amit
        };
69 11 amit
        FPEnvironmentImpl();
70 11 amit
        FPEnvironmentImpl(const FPEnvironmentImpl& env);
71 11 amit
        ~FPEnvironmentImpl();
72 11 amit
        FPEnvironmentImpl& operator = (const FPEnvironmentImpl& env);
73 11 amit
        void keepCurrentImpl();
74 11 amit
        static void clearFlagsImpl();
75 11 amit
        static bool isFlagImpl(FlagImpl flag);
76 11 amit
        static void setRoundingModeImpl(RoundingModeImpl mode);
77 11 amit
        static RoundingModeImpl getRoundingModeImpl();
78 11 amit
        static bool isInfiniteImpl(float value);
79 11 amit
        static bool isInfiniteImpl(double value);
80 11 amit
        static bool isInfiniteImpl(long double value);
81 11 amit
        static bool isNaNImpl(float value);
82 11 amit
        static bool isNaNImpl(double value);
83 11 amit
        static bool isNaNImpl(long double value);
84 11 amit
        static float copySignImpl(float target, float source);
85 11 amit
        static double copySignImpl(double target, double source);
86 11 amit
        static long double copySignImpl(long double target, long double source);
87 11 amit
88 11 amit
private:
89 11 amit
        unsigned _env;
90 11 amit
};
91 11 amit
92 11 amit
93 11 amit
//
94 11 amit
// inlines
95 11 amit
//
96 11 amit
inline bool FPEnvironmentImpl::isInfiniteImpl(float value)
97 11 amit
{
98 11 amit
        return _finite(value) == 0;
99 11 amit
}
100 11 amit
101 11 amit
102 11 amit
inline bool FPEnvironmentImpl::isInfiniteImpl(double value)
103 11 amit
{
104 11 amit
        return _finite(value) == 0;
105 11 amit
}
106 11 amit
107 11 amit
108 11 amit
inline bool FPEnvironmentImpl::isInfiniteImpl(long double value)
109 11 amit
{
110 11 amit
        return _finite(value) == 0;
111 11 amit
}
112 11 amit
113 11 amit
114 11 amit
inline bool FPEnvironmentImpl::isNaNImpl(float value)
115 11 amit
{
116 11 amit
        return _isnan(value) != 0;
117 11 amit
}
118 11 amit
119 11 amit
120 11 amit
inline bool FPEnvironmentImpl::isNaNImpl(double value)
121 11 amit
{
122 11 amit
        return _isnan(value) != 0;
123 11 amit
}
124 11 amit
125 11 amit
126 11 amit
inline bool FPEnvironmentImpl::isNaNImpl(long double value)
127 11 amit
{
128 11 amit
        return _isnan(value) != 0;
129 11 amit
}
130 11 amit
131 11 amit
132 11 amit
inline float FPEnvironmentImpl::copySignImpl(float target, float source)
133 11 amit
{
134 11 amit
        return float(_copysign(target, source));
135 11 amit
}
136 11 amit
137 11 amit
138 11 amit
inline double FPEnvironmentImpl::copySignImpl(double target, double source)
139 11 amit
{
140 11 amit
        return _copysign(target, source);
141 11 amit
}
142 11 amit
143 11 amit
144 11 amit
inline long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
145 11 amit
{
146 11 amit
        return (source > 0 && target > 0) || (source < 0 && target < 0) ? target : -target;
147 11 amit
}
148 11 amit
149 11 amit
150 11 amit
} // namespace Poco
151 11 amit
152 11 amit
153 11 amit
#endif // Foundation_FPEnvironment_WIN32_INCLUDED