Skip to content

Commit 1922ee9

Browse files
authored
Merge pull request #525 from cppalliance/develop
Merge for v1.0.1
2 parents 4b1413f + a199bd0 commit 1922ee9

File tree

12 files changed

+479
-189
lines changed

12 files changed

+479
-189
lines changed

doc/decimal/benchmarks.adoc

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ An example on Linux with b2: `../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_
2222

2323
== Comparisons
2424

25-
The benchmark for comparisons generates a random vector containing 2,000,000 elements and does operations `>`, `>=`, `<`, `<=`, `==`, and `!=` between `vec[i] and vec[i + 1]`.
25+
The benchmark for comparisons generates a random vector containing 2,000,000 elements and does operations `>`, `>=`, `<`, `\<=`, `==`, and `!=` between `vec[i] and vec[i + 1]`.
2626
This is repeated 5 times to generate stable results.
2727

2828
=== M1 macOS Results
@@ -32,20 +32,20 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
3232
|===
3333
| Type | Runtime (us) | Ratio to `double`
3434
| `float`
35-
| 9032
36-
| 1.589
35+
| 8764
36+
| 1.577
3737
| `double`
38-
| 5684
38+
| 5559
3939
| 1.000
4040
| `decimal32`
41-
| 285,453
42-
| 50.2204
41+
| 276,124
42+
| 49.672
4343
| `decimal64`
44-
| 352,644
45-
| 62.042
44+
| 355,999
45+
| 64.760
4646
| `decimal128`
47-
| 15,355,817
48-
| 2701.590
47+
| 989,028
48+
| 177.915
4949
|===
5050

5151
== Basic Operations
@@ -62,83 +62,83 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
6262
|===
6363
| Type | Runtime (us) | Ratio to `double`
6464
| `float`
65-
| 1641
66-
| 0.965
65+
| 2113
66+
| 0.739
6767
| `double`
68-
| 1708
68+
| 2860
6969
| 1.000
7070
| `decimal32`
71-
| 378,252
72-
| 221.459
71+
| 353,836
72+
| 123.719
7373
| `decimal64`
74-
| 589,313
75-
| 345.031
74+
| 409,098
75+
| 143.041
7676
| `decimal128`
77-
| 13,829,995
78-
| 8097.190
77+
| 2,418,039
78+
| 845.468
7979
|===
8080

8181
==== Subtraction
8282

8383
|===
8484
| Type | Runtime (us) | Ratio to `double`
8585
| `float`
86-
| 3633
87-
| 2.221
86+
| 1782
87+
| 1.061
8888
| `double`
89-
| 1636
89+
| 1680
9090
| 1.000
9191
| `decimal32`
92-
| 307,765
93-
| 188.120
92+
| 293,927
93+
| 174.957
9494
| `decimal64`
95-
| 461,442
96-
| 282.055
95+
| 329,425
96+
| 196.086
9797
| `decimal128`
98-
| 11,449,306
99-
| 6998.350
98+
| 1,527,261
99+
| 909.084
100100
|===
101101

102102
==== Multiplication
103103

104104
|===
105105
| Type | Runtime (us) | Ratio to `double`
106106
| `float`
107-
| 1678
108-
| 0.523
107+
| 1691
108+
| 0.979
109109
| `double`
110-
| 3209
110+
| 1728
111111
| 1.000
112112
| `decimal32`
113-
| 310,543
114-
| 96.773
113+
| 309,117
114+
| 178.887
115115
| `decimal64`
116-
| 570,938
117-
| 177.918
116+
| 408,010
117+
| 236.117
118118
| `decimal128`
119-
| 9,434,297
120-
| 2939.95
119+
| 2,506,105
120+
| 1450.292
121121
|===
122122

123123
==== Division
124124

125125
|===
126126
| Type | Runtime (us) | Ratio to `double`
127127
| `float`
128-
| 2019
129-
| 0.565
128+
| 2058
129+
| 0.846
130130
| `double`
131-
| 3572
131+
| 2434
132132
| 1.000
133133
| `decimal32`
134-
| 322,116
135-
| 90.178
134+
| 304,852
135+
| 125.247
136136
| `decimal64`
137-
| 734,173
138-
| 205.536
137+
| 519,990
138+
| 213.636
139139
| `decimal128`
140-
| 14,592,284
141-
| 4085.19
140+
| 3,534,909
141+
| 1452.304
142142
|===
143143

144144
== Selected Special Functions
@@ -155,20 +155,20 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
155155
|===
156156
| Type | Runtime (us) | Ratio to `double`
157157
| `float`
158-
| 1904
159-
| 0.565
158+
| 2021
159+
| 0.626
160160
| `double`
161-
| 3746
161+
| 3229
162162
| 1.000
163163
| `decimal32`
164-
| 5,050,241
165-
| 1341.72
164+
| 4,826,066
165+
| 1494.601
166166
| `decimal64`
167-
| 12,084,821
168-
| 3210.630
167+
| 7,780,637
168+
| 2409.612
169169
| `decimal128`
170-
| 275,779,340
171-
| 73267.60
170+
| 100,269,145
171+
| 31052.693
172172
|===
173173

174174
== `<charconv>`

include/boost/decimal/charconv.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <boost/decimal/detail/cmath/frexp10.hpp>
2020
#include <boost/decimal/detail/attributes.hpp>
2121
#include <boost/decimal/detail/countl.hpp>
22+
#include <boost/decimal/detail/remove_trailing_zeros.hpp>
2223

2324
#ifndef BOOST_DECIMAL_BUILD_MODULE
2425
#include <cstdint>
@@ -412,12 +413,11 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_fixed_impl(char* first, char* last, const
412413
// In general formatting we remove trailing 0s
413414
if (fmt == chars_format::general)
414415
{
415-
while (significand % 10 == 0)
416-
{
417-
significand /= 10;
418-
++exponent;
419-
--num_dig;
420-
}
416+
417+
const auto zeros_removal {remove_trailing_zeros(significand)};
418+
significand = zeros_removal.trimmed_number;
419+
exponent += static_cast<int>(zeros_removal.number_of_removed_zeros);
420+
num_dig -= static_cast<int>(zeros_removal.number_of_removed_zeros);
421421
}
422422
}
423423

include/boost/decimal/decimal128.hpp

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,21 +1937,15 @@ constexpr auto operator*(decimal128 lhs, decimal128 rhs) noexcept -> decimal128
19371937

19381938
auto lhs_sig {lhs.full_significand()};
19391939
auto lhs_exp {lhs.biased_exponent()};
1940-
1941-
while (lhs_sig % 10 == 0 && lhs_sig != 0)
1942-
{
1943-
lhs_sig /= 10;
1944-
++lhs_exp;
1945-
}
1940+
const auto lhs_zeros {detail::remove_trailing_zeros(lhs_sig)};
1941+
lhs_sig = lhs_zeros.trimmed_number;
1942+
lhs_exp += static_cast<std::int32_t>(lhs_zeros.number_of_removed_zeros);
19461943

19471944
auto rhs_sig {rhs.full_significand()};
19481945
auto rhs_exp {rhs.biased_exponent()};
1949-
1950-
while (rhs_sig % 10 == 0 && rhs_sig != 0)
1951-
{
1952-
rhs_sig /= 10;
1953-
++rhs_exp;
1954-
}
1946+
const auto rhs_zeros {detail::remove_trailing_zeros(rhs_sig)};
1947+
rhs_sig = rhs_zeros.trimmed_number;
1948+
rhs_exp += static_cast<std::int32_t>(rhs_zeros.number_of_removed_zeros);
19551949

19561950
const auto result {d128_mul_impl(lhs_sig, lhs_exp, lhs.isneg(),
19571951
rhs_sig, rhs_exp, rhs.isneg())};
@@ -1970,20 +1964,16 @@ constexpr auto operator*(decimal128 lhs, Integer rhs) noexcept
19701964

19711965
auto lhs_sig {lhs.full_significand()};
19721966
auto lhs_exp {lhs.biased_exponent()};
1973-
while (lhs_sig % 10 == 0 && lhs_sig != 0)
1974-
{
1975-
lhs_sig /= 10;
1976-
++lhs_exp;
1977-
}
1967+
const auto lhs_zeros {detail::remove_trailing_zeros(lhs_sig)};
1968+
lhs_sig = lhs_zeros.trimmed_number;
1969+
lhs_exp += static_cast<std::int32_t>(lhs_zeros.number_of_removed_zeros);
19781970
auto lhs_components {detail::decimal128_components{lhs_sig, lhs_exp, lhs.isneg()}};
19791971

19801972
auto rhs_sig {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
19811973
std::int32_t rhs_exp {0};
1982-
while (rhs_sig % 10 == 0 && rhs_sig != 0)
1983-
{
1984-
rhs_sig /= 10;
1985-
++rhs_exp;
1986-
}
1974+
const auto rhs_zeros {detail::remove_trailing_zeros(rhs_sig)};
1975+
rhs_sig = rhs_zeros.trimmed_number;
1976+
rhs_exp += static_cast<std::int32_t>(rhs_zeros.number_of_removed_zeros);
19871977
auto unsigned_sig_rhs {detail::make_positive_unsigned(rhs_sig)};
19881978
auto rhs_components {detail::decimal128_components{unsigned_sig_rhs, rhs_exp, (rhs < 0)}};
19891979

@@ -2433,25 +2423,18 @@ constexpr auto fmad128(decimal128 x, decimal128 y, decimal128 z) noexcept -> dec
24332423

24342424
auto sig_lhs {x.full_significand()};
24352425
auto exp_lhs {x.biased_exponent()};
2436-
2437-
while (sig_lhs % 10 == 0 && sig_lhs != 0)
2438-
{
2439-
sig_lhs /= 10;
2440-
++exp_lhs;
2441-
}
2426+
detail::normalize<decimal128>(sig_lhs, exp_lhs);
24422427

24432428
auto sig_rhs {y.full_significand()};
24442429
auto exp_rhs {y.biased_exponent()};
2445-
2446-
while (sig_rhs % 10 == 0 && sig_rhs != 0)
2447-
{
2448-
sig_rhs /= 10;
2449-
++exp_rhs;
2450-
}
2430+
detail::normalize<decimal128>(sig_rhs, exp_rhs);
24512431

24522432
auto mul_result {d128_mul_impl(sig_lhs, exp_lhs, x.isneg(), sig_rhs, exp_rhs, y.isneg())};
24532433
const decimal128 dec_result {mul_result.sig, mul_result.exp, mul_result.sign};
24542434

2435+
return dec_result + z;
2436+
2437+
/*
24552438
const auto res_add {detail::check_non_finite(dec_result, z)};
24562439
if (res_add != zero)
24572440
{
@@ -2493,6 +2476,7 @@ constexpr auto fmad128(decimal128 x, decimal128 y, decimal128 z) noexcept -> dec
24932476
}
24942477
24952478
return {result.sig, result.exp, result.sign};
2479+
*/
24962480
}
24972481

24982482
} //namespace decimal

0 commit comments

Comments
 (0)