Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
decimal/test/github_issue_1329.cpp at develop · samd2/decimal · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
samd2
/
decimal
Public
forked from
boostorg/decimal
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
decimal
/
test
/
github_issue_1329.cpp
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
233 lines (186 loc) · 6.02 KB
develop
Breadcrumbs
decimal
/
test
/
github_issue_1329.cpp
Copy path
Top
File metadata and controls
Code
Blame
233 lines (186 loc) · 6.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
//
Copyright 2026 Christopher Kormanyos
//
Distributed under the Boost Software License, Version 1.0.
//
https://www.boost.org/LICENSE_1_0.txt
#
if
defined(__clang__)
#
pragma
clang diagnostic push
#
pragma
clang diagnostic ignored "-Wfloat-equal"
#
pragma
clang diagnostic push
#
pragma
clang diagnostic ignored "-Wold-style-cast"
#
pragma
clang diagnostic push
#
pragma
clang diagnostic ignored "-Wundef"
#
if
(__clang_major__ > 12)
#
pragma
clang diagnostic push
#
pragma
clang diagnostic ignored "-Wunused-but-set-variable"
#
endif
#
elif
defined(__GNUC__)
#
pragma
GCC diagnostic push
#
pragma
GCC diagnostic ignored "-Wfloat-equal"
#
pragma
GCC diagnostic push
#
pragma
GCC diagnostic ignored "-Wold-style-cast"
#
pragma
GCC diagnostic push
#
pragma
GCC diagnostic ignored "-Wuseless-cast"
#
pragma
GCC diagnostic push
#
pragma
GCC diagnostic ignored "-Wrestrict"
#
endif
#
ifdef
_MSC_VER
#
pragma
warning(push)
#
pragma
warning(disable : 4996)
#
elif
(defined(__clang__) && (__clang_major__ >= 17))
#
pragma
clang diagnostic push
#
pragma
clang diagnostic ignored "-Wdeprecated-declarations"
#
endif
#
if
!defined(BOOST_MP_STANDALONE)
#
define
BOOST_MP_STANDALONE
#
endif
#
if
!defined(BOOST_MP_NO_EXCEPTIONS)
#
define
BOOST_MP_NO_EXCEPTIONS
#
endif
#
include
"
testing_config.hpp
"
#
include
<
boost/decimal/decimal128_t.hpp
>
#
include
<
boost/decimal/cmath.hpp
>
#
include
<
boost/decimal/iostream.hpp
>
#
include
<
boost/multiprecision/cpp_dec_float.hpp
>
#
include
<
boost/core/lightweight_test.hpp
>
#
include
<
chrono
>
#
include
<
random
>
#
include
<
iomanip
>
#
include
<
sstream
>
//
#define BOOST_DECIMAL_ISSUE_1329_SHOWS_STATS
namespace
local
{
template
<
typename
IntegralTimePointType,
typename
ClockType = std::chrono::high_resolution_clock>
auto
time_point
()
noexcept
-> IntegralTimePointType
{
using
local_integral_time_point_type = IntegralTimePointType;
using
local_clock_type = ClockType;
const
auto
current_now =
static_cast
<std::
uintmax_t
>
(
std::chrono::duration_cast<std::chrono::nanoseconds>
(
local_clock_type::now
().
time_since_epoch
()
).
count
()
);
return
static_cast
<local_integral_time_point_type>(current_now);
}
template
<
typename
NumericType>
auto
is_close_fraction
(
const
NumericType& a,
const
NumericType& b,
const
NumericType& tol)
noexcept
-> bool
{
using
std::fabs;
const
NumericType delta
{
(b ==
static_cast
<NumericType>(
0
)) ?
fabs
(a - b) :
fabs
(
1
- (a / b))
};
const
bool
result_is_ok { (delta < tol) };
return
result_is_ok;
}
auto
test_frexp_nohang128
() -> void
{
std::random_device rd;
std::mt19937_64
gen
(
rd
());
gen.
seed
(time_point<
typename
std::mt19937_64::result_type>());
auto
dis_denom =
std::uniform_int_distribution<std::
uint32_t
>
{
UINT32_C
(
104744
),
UINT32_C
(
999999
)
};
auto
dis_exp10 =
std::uniform_int_distribution<std::
int32_t
>
{
INT32_C
(-
4100
),
INT32_C
(+
4100
)
};
bool
result_is_ok {
true
};
#
if
defined(BOOST_DECIMAL_ISSUE_1329_SHOWS_STATS)
std::
uint32_t
count { };
double
total_time_ns { };
#
endif
#
if
!defined(BOOST_DECIMAL_REDUCE_TEST_DEPTH)
for
(std::
uint32_t
index {
UINT8_C
(
0
) }; index <
UINT32_C
(
1024
); ++index)
#
else
for
(std::
uint32_t
index {
UINT8_C
(
0
) }; index <
UINT32_C
(
32
); ++index)
#
endif
{
static_cast
<
void
>(index);
using
mp_type = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<
34
>, boost::multiprecision::et_off>;
const
auto
exp10 {
dis_exp10
(gen) };
const
auto
denom {
dis_denom
(gen) };
boost::decimal::
decimal128_t
arg_x {
UINT32_C
(
104743
), exp10 }; arg_x /= denom;
mp_type arg_mp {
UINT32_C
(
104743
) *
pow
(
mp_type
(
10
), exp10) }; arg_mp /= denom;
const
auto
start {
std::chrono::high_resolution_clock::now
() };
int
nexp2 { };
const
boost::decimal::
decimal128_t
trial {
frexp
(arg_x, &nexp2) };
const
auto
stop {
std::chrono::high_resolution_clock::now
() };
const
double
duration
{
static_cast
<
double
>
(
std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start).
count
()
)
};
int
n_mp { };
const
mp_type ctrl_mp {
frexp
(arg_mp, &n_mp) };
std::string str_ctrl { };
boost::decimal::
decimal128_t
ctrl_mp_as_dec { };
{
std::stringstream strm { };
strm <<
std::setprecision
(std::numeric_limits<boost::decimal::
decimal128_t
>::digits10) << ctrl_mp;
ctrl_mp_as_dec =
boost::decimal::decimal128_t
(strm.
str
());
}
result_is_ok = { (nexp2 == n_mp) &&
is_close_fraction
(trial, ctrl_mp_as_dec, std::numeric_limits<boost::decimal::
decimal128_t
>::
epsilon
() *
64
) };
BOOST_TEST
(result_is_ok);
#
if
defined(BOOST_DECIMAL_ISSUE_1329_SHOWS_STATS)
total_time_ns += duration;
++count;
{
const
double
avg_us {
static_cast
<
double
>(total_time_ns / count) /
1000.0
};
std::stringstream strm { };
strm << std::boolalpha
<<
"
result_is_ok:
"
<< result_is_ok
<<
"
, count:
"
<< count
<<
"
, avg_ns:
"
<< std::fixed
<<
std::setprecision
(
1
)
<< avg_us;
std::cout << strm.
str
() << std::endl;
}
#
else
static_cast
<
void
>(duration);
#
endif
if
(!result_is_ok)
{
break
;
}
}
}
}
//
namespace local
auto
main
() -> int
{
local::test_frexp_nohang128
();
return
boost::report_errors
();
}
#
ifdef
_MSC_VER
#
pragma
warning(pop)
#
elif
(defined(__clang__) && (__clang_major__ >= 17))
#
pragma
clang diagnostic pop
#
endif
#
if
defined(__clang__)
#
pragma
clang diagnostic pop
#
pragma
clang diagnostic pop
#
pragma
clang diagnostic pop
#
if
(__clang_major__ > 12)
#
pragma
clang diagnostic pop
#
endif
#
elif
defined(__GNUC__)
#
pragma
GCC diagnostic pop
#
pragma
GCC diagnostic pop
#
pragma
GCC diagnostic pop
#
pragma
GCC diagnostic pop
#
endif
You can’t perform that action at this time.