Skip to content

Commit

Permalink
Merge pull request #525 from cppalliance/develop
Browse files Browse the repository at this point in the history
Merge for v1.0.1
  • Loading branch information
mborland authored May 3, 2024
2 parents 4b1413f + a199bd0 commit 1922ee9
Show file tree
Hide file tree
Showing 12 changed files with 479 additions and 189 deletions.
110 changes: 55 additions & 55 deletions doc/decimal/benchmarks.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ An example on Linux with b2: `../../../b2 cxxstd=20 toolset=gcc-13 define=BOOST_

== Comparisons

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

=== M1 macOS Results
Expand All @@ -32,20 +32,20 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 9032
| 1.589
| 8764
| 1.577
| `double`
| 5684
| 5559
| 1.000
| `decimal32`
| 285,453
| 50.2204
| 276,124
| 49.672
| `decimal64`
| 352,644
| 62.042
| 355,999
| 64.760
| `decimal128`
| 15,355,817
| 2701.590
| 989,028
| 177.915
|===

== Basic Operations
Expand All @@ -62,83 +62,83 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 1641
| 0.965
| 2113
| 0.739
| `double`
| 1708
| 2860
| 1.000
| `decimal32`
| 378,252
| 221.459
| 353,836
| 123.719
| `decimal64`
| 589,313
| 345.031
| 409,098
| 143.041
| `decimal128`
| 13,829,995
| 8097.190
| 2,418,039
| 845.468
|===

==== Subtraction

|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 3633
| 2.221
| 1782
| 1.061
| `double`
| 1636
| 1680
| 1.000
| `decimal32`
| 307,765
| 188.120
| 293,927
| 174.957
| `decimal64`
| 461,442
| 282.055
| 329,425
| 196.086
| `decimal128`
| 11,449,306
| 6998.350
| 1,527,261
| 909.084
|===

==== Multiplication

|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 1678
| 0.523
| 1691
| 0.979
| `double`
| 3209
| 1728
| 1.000
| `decimal32`
| 310,543
| 96.773
| 309,117
| 178.887
| `decimal64`
| 570,938
| 177.918
| 408,010
| 236.117
| `decimal128`
| 9,434,297
| 2939.95
| 2,506,105
| 1450.292
|===

==== Division

|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 2019
| 0.565
| 2058
| 0.846
| `double`
| 3572
| 2434
| 1.000
| `decimal32`
| 322,116
| 90.178
| 304,852
| 125.247
| `decimal64`
| 734,173
| 205.536
| 519,990
| 213.636
| `decimal128`
| 14,592,284
| 4085.19
| 3,534,909
| 1452.304
|===

== Selected Special Functions
Expand All @@ -155,20 +155,20 @@ Run using a Macbook pro with M1 pro chipset running macOS Sonoma 14.4.1 and home
|===
| Type | Runtime (us) | Ratio to `double`
| `float`
| 1904
| 0.565
| 2021
| 0.626
| `double`
| 3746
| 3229
| 1.000
| `decimal32`
| 5,050,241
| 1341.72
| 4,826,066
| 1494.601
| `decimal64`
| 12,084,821
| 3210.630
| 7,780,637
| 2409.612
| `decimal128`
| 275,779,340
| 73267.60
| 100,269,145
| 31052.693
|===

== `<charconv>`
Expand Down
12 changes: 6 additions & 6 deletions include/boost/decimal/charconv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <boost/decimal/detail/cmath/frexp10.hpp>
#include <boost/decimal/detail/attributes.hpp>
#include <boost/decimal/detail/countl.hpp>
#include <boost/decimal/detail/remove_trailing_zeros.hpp>

#ifndef BOOST_DECIMAL_BUILD_MODULE
#include <cstdint>
Expand Down Expand Up @@ -412,12 +413,11 @@ BOOST_DECIMAL_CONSTEXPR auto to_chars_fixed_impl(char* first, char* last, const
// In general formatting we remove trailing 0s
if (fmt == chars_format::general)
{
while (significand % 10 == 0)
{
significand /= 10;
++exponent;
--num_dig;
}

const auto zeros_removal {remove_trailing_zeros(significand)};
significand = zeros_removal.trimmed_number;
exponent += static_cast<int>(zeros_removal.number_of_removed_zeros);
num_dig -= static_cast<int>(zeros_removal.number_of_removed_zeros);
}
}

Expand Down
52 changes: 18 additions & 34 deletions include/boost/decimal/decimal128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1937,21 +1937,15 @@ constexpr auto operator*(decimal128 lhs, decimal128 rhs) noexcept -> decimal128

auto lhs_sig {lhs.full_significand()};
auto lhs_exp {lhs.biased_exponent()};

while (lhs_sig % 10 == 0 && lhs_sig != 0)
{
lhs_sig /= 10;
++lhs_exp;
}
const auto lhs_zeros {detail::remove_trailing_zeros(lhs_sig)};
lhs_sig = lhs_zeros.trimmed_number;
lhs_exp += static_cast<std::int32_t>(lhs_zeros.number_of_removed_zeros);

auto rhs_sig {rhs.full_significand()};
auto rhs_exp {rhs.biased_exponent()};

while (rhs_sig % 10 == 0 && rhs_sig != 0)
{
rhs_sig /= 10;
++rhs_exp;
}
const auto rhs_zeros {detail::remove_trailing_zeros(rhs_sig)};
rhs_sig = rhs_zeros.trimmed_number;
rhs_exp += static_cast<std::int32_t>(rhs_zeros.number_of_removed_zeros);

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

auto lhs_sig {lhs.full_significand()};
auto lhs_exp {lhs.biased_exponent()};
while (lhs_sig % 10 == 0 && lhs_sig != 0)
{
lhs_sig /= 10;
++lhs_exp;
}
const auto lhs_zeros {detail::remove_trailing_zeros(lhs_sig)};
lhs_sig = lhs_zeros.trimmed_number;
lhs_exp += static_cast<std::int32_t>(lhs_zeros.number_of_removed_zeros);
auto lhs_components {detail::decimal128_components{lhs_sig, lhs_exp, lhs.isneg()}};

auto rhs_sig {static_cast<detail::uint128>(detail::make_positive_unsigned(rhs))};
std::int32_t rhs_exp {0};
while (rhs_sig % 10 == 0 && rhs_sig != 0)
{
rhs_sig /= 10;
++rhs_exp;
}
const auto rhs_zeros {detail::remove_trailing_zeros(rhs_sig)};
rhs_sig = rhs_zeros.trimmed_number;
rhs_exp += static_cast<std::int32_t>(rhs_zeros.number_of_removed_zeros);
auto unsigned_sig_rhs {detail::make_positive_unsigned(rhs_sig)};
auto rhs_components {detail::decimal128_components{unsigned_sig_rhs, rhs_exp, (rhs < 0)}};

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

auto sig_lhs {x.full_significand()};
auto exp_lhs {x.biased_exponent()};

while (sig_lhs % 10 == 0 && sig_lhs != 0)
{
sig_lhs /= 10;
++exp_lhs;
}
detail::normalize<decimal128>(sig_lhs, exp_lhs);

auto sig_rhs {y.full_significand()};
auto exp_rhs {y.biased_exponent()};

while (sig_rhs % 10 == 0 && sig_rhs != 0)
{
sig_rhs /= 10;
++exp_rhs;
}
detail::normalize<decimal128>(sig_rhs, exp_rhs);

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

return dec_result + z;

/*
const auto res_add {detail::check_non_finite(dec_result, z)};
if (res_add != zero)
{
Expand Down Expand Up @@ -2493,6 +2476,7 @@ constexpr auto fmad128(decimal128 x, decimal128 y, decimal128 z) noexcept -> dec
}
return {result.sig, result.exp, result.sign};
*/
}

} //namespace decimal
Expand Down
Loading

0 comments on commit 1922ee9

Please sign in to comment.