Skip to content

Commit d4bea7a

Browse files
committed
Merge branch 'develop' into t_gamma_bama_jama
2 parents 7582109 + b2798ed commit d4bea7a

File tree

12 files changed

+356
-132
lines changed

12 files changed

+356
-132
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,31 @@ This library is not an official boost library, and is under active development.
1818
# How To Use The Library
1919

2020
This library is header only, and contains no dependencies.
21-
It can either be copied into the directory of your choice, or installed with CMake.
21+
22+
## CMake
23+
24+
````
25+
git clone https://github.com/cppalliance/decimal
26+
cd decimal
27+
mkdir build && cd build
28+
cmake .. OR cmake .. -DCMAKE_INSTALL_PREFIX=/your/custom/path
29+
cmake --install .
30+
````
31+
32+
## vcpkg
33+
34+
````
35+
git clone https://github.com/cppalliance/decimal
36+
cd decimal
37+
vcpkg install decimal --overlay-ports=ports/decimal
38+
````
39+
40+
## Conan
41+
42+
````
43+
git clone https://github.com/cppalliance/decimal
44+
conan create decimal/conan --build missing
45+
````
2246

2347
# Supported Platforms
2448

conan/conanfile.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from conan import ConanFile
2+
from conan.errors import (
3+
ConanException,
4+
ConanInvalidConfiguration,
5+
)
6+
from conan.tools.files import copy
7+
from conan.tools.build import check_min_cppstd
8+
from conan.tools.cmake import (
9+
cmake_layout,
10+
CMake,
11+
CMakeDeps,
12+
CMakeToolchain,
13+
)
14+
from conan.tools.scm import Version
15+
16+
import os
17+
18+
required_conan_version = ">=1.53.0"
19+
20+
class CharconvConan(ConanFile):
21+
name = "boost_decimal"
22+
version = "1.0.0"
23+
description = "Boost provides free peer-reviewed portable C++ source libraries"
24+
url = "https://github.com/cppalliance/decimal"
25+
homepage = "https://github.com/cppalliance/decimal"
26+
license = "BSL-1.0"
27+
topics = ("decimal-binary", "conversion")
28+
29+
settings = "os", "arch", "compiler", "build_type"
30+
31+
options = {
32+
"shared": [True, False],
33+
"fPIC": [True, False],
34+
}
35+
default_options = {
36+
"shared": False,
37+
"fPIC": True,
38+
}
39+
40+
requires = "boost/[>=1.82.0]"
41+
42+
@property
43+
def _min_compiler_version_default_cxx14(self):
44+
return {
45+
"apple-clang": 99,
46+
"gcc": 6,
47+
"clang": 6,
48+
"Visual Studio": 14, # guess
49+
"msvc": 192,
50+
}.get(str(self.settings.compiler))
51+
52+
def config_options(self):
53+
if self.settings.os == "Windows":
54+
del self.options.fPIC
55+
56+
def validate(self):
57+
if self.settings.compiler.get_safe("cppstd"):
58+
check_min_cppstd(self, 14)
59+
else:
60+
version_cxx14_standard_json = self._min_compiler_version_default_cxx14
61+
if not version_cxx14_standard_json:
62+
self.output.warning("Assuming the compiler supports c++14 by default")
63+
elif Version(self.settings.compiler.version) < version_cxx14_standard_json:
64+
raise ConanInvalidConfiguration("Boost.Decimal requires C++14")
65+
66+
def layout(self):
67+
self.folders.root = ".."
68+
cmake_layout(self, build_folder="bin")
69+
70+
def export_sources(self):
71+
src = os.path.join(self.recipe_folder, "..")
72+
copy(self, "CMakeLists.txt", src, self.export_sources_folder)
73+
copy(self, "LICENSE", src, self.export_sources_folder)
74+
copy(self, "include*", src, self.export_sources_folder)
75+
copy(self, "conan/*.cmake", src, self.export_sources_folder)
76+
77+
def generate(self):
78+
boost = self.dependencies["boost"]
79+
80+
tc = CMakeToolchain(self)
81+
tc.variables["BOOST_SUPERPROJECT_VERSION"] = boost.ref.version
82+
tc.variables["CMAKE_PROJECT_boost_decimal_INCLUDE"] = os.path.join(
83+
self.source_folder, "conan", "targets.cmake")
84+
tc.generate()
85+
86+
deps = CMakeDeps(self)
87+
deps.generate()
88+
89+
def build(self):
90+
cmake = CMake(self)
91+
cmake.configure()
92+
cmake.build()
93+
94+
def package(self):
95+
libdir = os.path.join(self.package_folder, "lib")
96+
97+
copy(self, "include/*", self.source_folder, self.package_folder)
98+
99+
copy(self, "LICENSE", self.source_folder, self.package_folder)
100+
101+
def package_info(self):
102+
self.cpp_info.libs = ["boost_decimal"]

conan/targets.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
find_package(Boost)

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

0 commit comments

Comments
 (0)