Accepting request 979674 from home:StefanBruens:branches:devel:libraries:c_c++

- Fix failing conversion of cpp_dec_float to double, depending on
  locale (gh#boostorg/multiprecision#464, boo#1199968).
  Add boost-mp-locale-fix.patch

OBS-URL: https://build.opensuse.org/request/show/979674
OBS-URL: https://build.opensuse.org/package/show/devel:libraries:c_c++/boost?expand=0&rev=301
This commit is contained in:
Dirk Mueller 2022-05-29 18:44:51 +00:00 committed by Git OBS Bridge
parent 8756c4963c
commit 956ce2a015
3 changed files with 117 additions and 0 deletions

108
boost-mp-locale-fix.patch Normal file
View File

@ -0,0 +1,108 @@
From b30cfbb5dd7bf0a03730a5e25d35b4fd61add6e7 Mon Sep 17 00:00:00 2001
From: Matt Borland <matt@mattborland.com>
Date: Sat, 28 May 2022 08:53:35 -0700
Subject: [PATCH] Fix for issue #464
---
.../boost/multiprecision/cpp_dec_float.hpp | 22 +++++++++++--
test/Jamfile.v2 | 1 +
test/git_issue_464.cpp | 31 +++++++++++++++++++
3 files changed, 52 insertions(+), 2 deletions(-)
create mode 100644 test/git_issue_464.cpp
diff --git a/include/boost/multiprecision/cpp_dec_float.hpp b/include/boost/multiprecision/cpp_dec_float.hpp
index bed38d5cf..074073827 100644
--- a/boost/multiprecision/cpp_dec_float.hpp
+++ b/boost/multiprecision/cpp_dec_float.hpp
@@ -26,6 +26,8 @@
#include <string>
#include <limits>
#include <stdexcept>
+#include <sstream>
+#include <locale>
#include <boost/multiprecision/detail/standalone_config.hpp>
#include <boost/multiprecision/number.hpp>
#include <boost/multiprecision/detail/fpclassify.hpp>
@@ -1603,7 +1605,15 @@ double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_double() const
: -std::numeric_limits<double>::infinity());
}
- return std::strtod(str(std::numeric_limits<double>::digits10 + (2 + 1), std::ios_base::scientific).c_str(), nullptr);
+ std::stringstream ss;
+ ss.imbue(std::locale::classic());
+
+ ss << str(std::numeric_limits<double>::digits10 + (2 + 1), std::ios_base::scientific);
+
+ double d;
+ ss >> d;
+
+ return d;
}
template <unsigned Digits10, class ExponentType, class Allocator>
@@ -1642,7 +1652,15 @@ long double cpp_dec_float<Digits10, ExponentType, Allocator>::extract_long_doubl
: -std::numeric_limits<long double>::infinity());
}
- return std::strtold(str(std::numeric_limits<long double>::digits10 + (2 + 1), std::ios_base::scientific).c_str(), nullptr);
+ std::stringstream ss;
+ ss.imbue(std::locale::classic());
+
+ ss << str(std::numeric_limits<long double>::digits10 + (2 + 1), std::ios_base::scientific);
+
+ long double ld;
+ ss >> ld;
+
+ return ld;
}
template <unsigned Digits10, class ExponentType, class Allocator>
diff --git a/test/Jamfile.v2 b/test/Jamfile.v2
index 4ad012273..f5d88edf2 100644
--- a/libs/multiprecision/test/Jamfile.v2
+++ b/libs/multiprecision/test/Jamfile.v2
@@ -1176,6 +1176,7 @@ test-suite misc :
[ run git_issue_426.cpp : : : [ check-target-builds ../config//has_mpfr : <source>gmp <source>mpfr <define>TEST_MPFR ] [ check-target-builds ../config//has_float128 : <source>quadmath <define>TEST_FLOAT128 ] ]
[ run git_issue_277.cpp ]
[ run git_issue_313.cpp ]
+ [ run git_issue_464.cpp ]
[ compile git_issue_98.cpp :
[ check-target-builds ../config//has_float128 : <define>TEST_FLOAT128 <source>quadmath : ]
[ check-target-builds ../config//has_gmp : <define>TEST_GMP <source>gmp : ]
diff --git a/test/git_issue_464.cpp b/test/git_issue_464.cpp
new file mode 100644
index 000000000..dc9d0054a
--- /dev/null
+++ b/libs/multiprecision/test/git_issue_464.cpp
@@ -0,0 +1,31 @@
+///////////////////////////////////////////////////////////////////////////////
+// Copyright 2022 Matt Borland. Distributed under the Boost
+// Software License, Version 1.0. (See accompanying file
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+//
+// See: https://github.com/boostorg/multiprecision/issues/464
+
+#include <boost/multiprecision/cpp_dec_float.hpp>
+#include <locale>
+#include "test.hpp"
+
+template <typename T>
+void test()
+{
+ auto a = boost::multiprecision::cpp_dec_float_50 {12345};
+
+ auto d1 = a.convert_to<T>();
+
+ std::locale::global(std::locale("de_DE"));
+ auto d2 = a.convert_to<T>();
+
+ BOOST_CHECK_EQUAL(d1, d2);
+}
+
+int main(void)
+{
+ test<double>();
+ test<long double>();
+
+ return boost::report_errors();
+}

View File

@ -1,3 +1,10 @@
-------------------------------------------------------------------
Sun May 29 12:51:47 UTC 2022 - Stefan Brüns <stefan.bruens@rwth-aachen.de>
- Fix failing conversion of cpp_dec_float to double, depending on
locale (gh#boostorg/multiprecision#464, boo#1199968).
Add boost-mp-locale-fix.patch
-------------------------------------------------------------------
Fri Apr 15 00:23:22 UTC 2022 - Dirk Müller <dmueller@suse.com>

View File

@ -266,6 +266,7 @@ Patch20: python_library_name.patch
Patch21: boost-remove-cmakedir.patch
Patch22: boost-process.patch
Patch23: https://www.boost.org/patches/1_79_0/0001-json-array-erase-relocate.patch
Patch24: boost-mp-locale-fix.patch
BuildRequires: fdupes
BuildRequires: gmp-devel
BuildRequires: libbz2-devel
@ -1260,6 +1261,7 @@ find -type f ! \( -name \*.sh -o -name \*.py -o -name \*.pl \) -exec chmod -x {}
%patch21 -p1
%patch22 -p2
%patch23 -p1
%patch24 -p1
%build
find . -type f -exec chmod u+w {} +