Skip to content

Commit

Permalink
Merge branch 'develop' into t_gamma_bama_jama
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed May 1, 2024
2 parents 7582109 + b2798ed commit d4bea7a
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 132 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,31 @@ This library is not an official boost library, and is under active development.
# How To Use The Library

This library is header only, and contains no dependencies.
It can either be copied into the directory of your choice, or installed with CMake.

## CMake

````
git clone https://github.com/cppalliance/decimal
cd decimal
mkdir build && cd build
cmake .. OR cmake .. -DCMAKE_INSTALL_PREFIX=/your/custom/path
cmake --install .
````

## vcpkg

````
git clone https://github.com/cppalliance/decimal
cd decimal
vcpkg install decimal --overlay-ports=ports/decimal
````

## Conan

````
git clone https://github.com/cppalliance/decimal
conan create decimal/conan --build missing
````

# Supported Platforms

Expand Down
102 changes: 102 additions & 0 deletions conan/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from conan import ConanFile
from conan.errors import (
ConanException,
ConanInvalidConfiguration,
)
from conan.tools.files import copy
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import (
cmake_layout,
CMake,
CMakeDeps,
CMakeToolchain,
)
from conan.tools.scm import Version

import os

required_conan_version = ">=1.53.0"

class CharconvConan(ConanFile):
name = "boost_decimal"
version = "1.0.0"
description = "Boost provides free peer-reviewed portable C++ source libraries"
url = "https://github.com/cppalliance/decimal"
homepage = "https://github.com/cppalliance/decimal"
license = "BSL-1.0"
topics = ("decimal-binary", "conversion")

settings = "os", "arch", "compiler", "build_type"

options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

requires = "boost/[>=1.82.0]"

@property
def _min_compiler_version_default_cxx14(self):
return {
"apple-clang": 99,
"gcc": 6,
"clang": 6,
"Visual Studio": 14, # guess
"msvc": 192,
}.get(str(self.settings.compiler))

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 14)
else:
version_cxx14_standard_json = self._min_compiler_version_default_cxx14
if not version_cxx14_standard_json:
self.output.warning("Assuming the compiler supports c++14 by default")
elif Version(self.settings.compiler.version) < version_cxx14_standard_json:
raise ConanInvalidConfiguration("Boost.Decimal requires C++14")

def layout(self):
self.folders.root = ".."
cmake_layout(self, build_folder="bin")

def export_sources(self):
src = os.path.join(self.recipe_folder, "..")
copy(self, "CMakeLists.txt", src, self.export_sources_folder)
copy(self, "LICENSE", src, self.export_sources_folder)
copy(self, "include*", src, self.export_sources_folder)
copy(self, "conan/*.cmake", src, self.export_sources_folder)

def generate(self):
boost = self.dependencies["boost"]

tc = CMakeToolchain(self)
tc.variables["BOOST_SUPERPROJECT_VERSION"] = boost.ref.version
tc.variables["CMAKE_PROJECT_boost_decimal_INCLUDE"] = os.path.join(
self.source_folder, "conan", "targets.cmake")
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
libdir = os.path.join(self.package_folder, "lib")

copy(self, "include/*", self.source_folder, self.package_folder)

copy(self, "LICENSE", self.source_folder, self.package_folder)

def package_info(self):
self.cpp_info.libs = ["boost_decimal"]
1 change: 1 addition & 0 deletions conan/targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find_package(Boost)
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
Loading

0 comments on commit d4bea7a

Please sign in to comment.