1 | // |
---|
2 | // FPEnvironment_DEC.cpp |
---|
3 | // |
---|
4 | // $Id: //poco/1.3/Foundation/src/FPEnvironment_DEC.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 | // Permission is hereby granted, free of charge, to any person or organization |
---|
14 | // obtaining a copy of the software and accompanying documentation covered by |
---|
15 | // this license (the "Software") to use, reproduce, display, distribute, |
---|
16 | // execute, and transmit the Software, and to prepare derivative works of the |
---|
17 | // Software, and to permit third-parties to whom the Software is furnished to |
---|
18 | // do so, all subject to the following: |
---|
19 | // |
---|
20 | // The copyright notices in the Software and this entire statement, including |
---|
21 | // the above license grant, this restriction and the following disclaimer, |
---|
22 | // must be included in all copies of the Software, in whole or in part, and |
---|
23 | // all derivative works of the Software, unless such copies or derivative |
---|
24 | // works are solely in the form of machine-executable object code generated by |
---|
25 | // a source language processor. |
---|
26 | // |
---|
27 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
28 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
29 | // FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT |
---|
30 | // SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE |
---|
31 | // FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, |
---|
32 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
33 | // DEALINGS IN THE SOFTWARE. |
---|
34 | // |
---|
35 | |
---|
36 | |
---|
37 | // |
---|
38 | // _XOPEN_SOURCE disables the ieee fp functions |
---|
39 | // in <math.h>, therefore we undefine it for this file. |
---|
40 | // |
---|
41 | #undef _XOPEN_SOURCE |
---|
42 | |
---|
43 | |
---|
44 | #include <math.h> |
---|
45 | #include <fp.h> |
---|
46 | #include <fp_class.h> |
---|
47 | #if defined(__VMS) |
---|
48 | #include <starlet.h> |
---|
49 | #endif |
---|
50 | #include "Poco/FPEnvironment_DEC.h" |
---|
51 | |
---|
52 | |
---|
53 | namespace Poco { |
---|
54 | |
---|
55 | |
---|
56 | FPEnvironmentImpl::FPEnvironmentImpl() |
---|
57 | { |
---|
58 | #if defined(__VMS) |
---|
59 | #pragma pointer_size save |
---|
60 | #pragma pointer_size 32 |
---|
61 | struct _ieee env; |
---|
62 | sys$ieee_set_fp_control(0, 0, &env); |
---|
63 | #pragma pointer_size restore |
---|
64 | _env = env; |
---|
65 | #else |
---|
66 | _env = ieee_get_fp_control(); |
---|
67 | #endif |
---|
68 | } |
---|
69 | |
---|
70 | |
---|
71 | FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env) |
---|
72 | { |
---|
73 | _env = env._env; |
---|
74 | } |
---|
75 | |
---|
76 | |
---|
77 | FPEnvironmentImpl::~FPEnvironmentImpl() |
---|
78 | { |
---|
79 | #if defined(__VMS) |
---|
80 | #pragma pointer_size save |
---|
81 | #pragma pointer_size 32 |
---|
82 | struct _ieee mask; |
---|
83 | mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF; |
---|
84 | struct _ieee env = _env; |
---|
85 | sys$ieee_set_fp_control(&mask, &env, 0); |
---|
86 | #pragma pointer_size restore |
---|
87 | #else |
---|
88 | ieee_set_fp_control(_env); |
---|
89 | #endif |
---|
90 | } |
---|
91 | |
---|
92 | |
---|
93 | FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env) |
---|
94 | { |
---|
95 | _env = env._env; |
---|
96 | return *this; |
---|
97 | } |
---|
98 | |
---|
99 | |
---|
100 | bool FPEnvironmentImpl::isInfiniteImpl(float value) |
---|
101 | { |
---|
102 | int cls = fp_classf(value); |
---|
103 | return cls == FP_POS_INF || cls == FP_NEG_INF; |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | bool FPEnvironmentImpl::isInfiniteImpl(double value) |
---|
108 | { |
---|
109 | int cls = fp_class(value); |
---|
110 | return cls == FP_POS_INF || cls == FP_NEG_INF; |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | bool FPEnvironmentImpl::isInfiniteImpl(long double value) |
---|
115 | { |
---|
116 | int cls = fp_classl(value); |
---|
117 | return cls == FP_POS_INF || cls == FP_NEG_INF; |
---|
118 | } |
---|
119 | |
---|
120 | |
---|
121 | bool FPEnvironmentImpl::isNaNImpl(float value) |
---|
122 | { |
---|
123 | return isnanf(value) != 0; |
---|
124 | } |
---|
125 | |
---|
126 | |
---|
127 | bool FPEnvironmentImpl::isNaNImpl(double value) |
---|
128 | { |
---|
129 | return isnan(value) != 0; |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | bool FPEnvironmentImpl::isNaNImpl(long double value) |
---|
134 | { |
---|
135 | return isnanl(value) != 0; |
---|
136 | } |
---|
137 | |
---|
138 | |
---|
139 | float FPEnvironmentImpl::copySignImpl(float target, float source) |
---|
140 | { |
---|
141 | return copysignf(target, source); |
---|
142 | } |
---|
143 | |
---|
144 | |
---|
145 | double FPEnvironmentImpl::copySignImpl(double target, double source) |
---|
146 | { |
---|
147 | return copysign(target, source); |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | long double FPEnvironmentImpl::copySignImpl(long double target, long double source) |
---|
152 | { |
---|
153 | return copysignl(target, source); |
---|
154 | } |
---|
155 | |
---|
156 | |
---|
157 | void FPEnvironmentImpl::keepCurrentImpl() |
---|
158 | { |
---|
159 | #if defined(__VMS) |
---|
160 | #pragma pointer_size save |
---|
161 | #pragma pointer_size 32 |
---|
162 | struct _ieee env; |
---|
163 | sys$ieee_set_fp_control(0, 0, &env); |
---|
164 | #pragma pointer_size restore |
---|
165 | _env = env; |
---|
166 | #else |
---|
167 | ieee_set_fp_control(_env); |
---|
168 | #endif |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | void FPEnvironmentImpl::clearFlagsImpl() |
---|
173 | { |
---|
174 | #if defined(__VMS) |
---|
175 | #pragma pointer_size save |
---|
176 | #pragma pointer_size 32 |
---|
177 | struct _ieee mask; |
---|
178 | mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF; |
---|
179 | struct _ieee clr; |
---|
180 | clr.ieee$q_flags = 0; |
---|
181 | sys$ieee_set_fp_control(&mask, &clr, 0); |
---|
182 | #pragma pointer_size restore |
---|
183 | #else |
---|
184 | ieee_set_fp_control(0); |
---|
185 | #endif |
---|
186 | } |
---|
187 | |
---|
188 | |
---|
189 | bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag) |
---|
190 | { |
---|
191 | #if defined(__VMS) |
---|
192 | #pragma pointer_size save |
---|
193 | #pragma pointer_size 32 |
---|
194 | struct _ieee flags; |
---|
195 | sys$ieee_set_fp_control(0, 0, &flags); |
---|
196 | return (flags.ieee$q_flags & flag) != 0; |
---|
197 | #pragma pointer_size restore |
---|
198 | #else |
---|
199 | return (ieee_get_fp_control() & flag) != 0; |
---|
200 | #endif |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode) |
---|
205 | { |
---|
206 | // not supported |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl() |
---|
211 | { |
---|
212 | // not supported |
---|
213 | return FPEnvironmentImpl::RoundingModeImpl(0); |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | } // namespace Poco |
---|