aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/poco/Foundation/src/FPEnvironment_DEC.cpp
blob: ebab43e906a5e205e883d8fea8622bae6992fe8e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// FPEnvironment_DEC.cpp
//
// Library: Foundation
// Package: Core
// Module:  FPEnvironment
//
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier:	BSL-1.0
//


//
// _XOPEN_SOURCE disables the ieee fp functions
// in <math.h>, therefore we undefine it for this file.
//
#undef _XOPEN_SOURCE


#include <math.h>
#include <fp.h>
#include <fp_class.h>
#if defined(__VMS)
#error #include <starlet.h>
#endif
#include "Poco/FPEnvironment_DEC.h"


namespace Poco {


FPEnvironmentImpl::FPEnvironmentImpl()
{
#if defined(__VMS)
	#pragma pointer_size save
	#pragma pointer_size 32
	struct _ieee env;
	sys$ieee_set_fp_control(0, 0, &env);
	#pragma pointer_size restore
	_env = env;
#else
	_env = ieee_get_fp_control();
#endif
}


FPEnvironmentImpl::FPEnvironmentImpl(const FPEnvironmentImpl& env)
{
	_env = env._env;
}


FPEnvironmentImpl::~FPEnvironmentImpl()
{
#if defined(__VMS)
	#pragma pointer_size save
	#pragma pointer_size 32
	struct _ieee mask;
	mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF;
	struct _ieee env = _env;
	sys$ieee_set_fp_control(&mask, &env, 0);
	#pragma pointer_size restore
#else
	ieee_set_fp_control(_env);
#endif
}


FPEnvironmentImpl& FPEnvironmentImpl::operator = (const FPEnvironmentImpl& env)
{
	_env = env._env;
	return *this;
}


bool FPEnvironmentImpl::isInfiniteImpl(float value)
{
	int cls = fp_classf(value);
	return cls == FP_POS_INF || cls == FP_NEG_INF;
}


bool FPEnvironmentImpl::isInfiniteImpl(double value)
{
	int cls = fp_class(value);
	return cls == FP_POS_INF || cls == FP_NEG_INF;
}


bool FPEnvironmentImpl::isInfiniteImpl(long double value)
{
	int cls = fp_classl(value);
	return cls == FP_POS_INF || cls == FP_NEG_INF;
}


bool FPEnvironmentImpl::isNaNImpl(float value)
{
	return isnanf(value) != 0;
}


bool FPEnvironmentImpl::isNaNImpl(double value)
{
	return isnan(value) != 0;
}


bool FPEnvironmentImpl::isNaNImpl(long double value)
{
	return isnanl(value) != 0;
}


float FPEnvironmentImpl::copySignImpl(float target, float source)
{
	return copysignf(target, source);
}


double FPEnvironmentImpl::copySignImpl(double target, double source)
{
	return copysign(target, source);
}


long double FPEnvironmentImpl::copySignImpl(long double target, long double source)
{
	return copysignl(target, source);
}


void FPEnvironmentImpl::keepCurrentImpl()
{
#if defined(__VMS)
	#pragma pointer_size save
	#pragma pointer_size 32
	struct _ieee env;
	sys$ieee_set_fp_control(0, 0, &env);
	#pragma pointer_size restore
	_env = env;
#else
	ieee_set_fp_control(_env);
#endif
}


void FPEnvironmentImpl::clearFlagsImpl()
{
#if defined(__VMS)
	#pragma pointer_size save
	#pragma pointer_size 32
	struct _ieee mask;
	mask.ieee$q_flags = 0xFFFFFFFFFFFFFFFF;
	struct _ieee clr;
	clr.ieee$q_flags  = 0;
	sys$ieee_set_fp_control(&mask, &clr, 0);
	#pragma pointer_size restore
#else
	ieee_set_fp_control(0);
#endif
}


bool FPEnvironmentImpl::isFlagImpl(FlagImpl flag)
{
#if defined(__VMS)
	#pragma pointer_size save
	#pragma pointer_size 32
	struct _ieee flags;
	sys$ieee_set_fp_control(0, 0, &flags);
	return (flags.ieee$q_flags & flag) != 0;
	#pragma pointer_size restore
#else
	return (ieee_get_fp_control() & flag) != 0;
#endif
}


void FPEnvironmentImpl::setRoundingModeImpl(RoundingModeImpl mode)
{
	// not supported
}


FPEnvironmentImpl::RoundingModeImpl FPEnvironmentImpl::getRoundingModeImpl()
{
	// not supported
	return FPEnvironmentImpl::RoundingModeImpl(0);
}


} // namespace Poco