Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 860498 - dev-libs/boost-1.79.0: cpp_dec_float<>::convert_to<double>() fails when locale radix character is ','
Summary: dev-libs/boost-1.79.0: cpp_dec_float<>::convert_to<double>() fails when local...
Status: RESOLVED OBSOLETE
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: David Seifert
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2022-07-24 10:15 UTC by Marcus Comstedt
Modified: 2022-12-03 13:07 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Upstreams patch, with filenames modified to match the unified boost dist (cpp_dec_float_locale.patch,5.47 KB, patch)
2022-07-24 10:16 UTC, Marcus Comstedt
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Comstedt 2022-07-24 10:15:45 UTC
When the current locale uses ',' as the radix character instead of '.', the result of cpp_dec_float<>::convert_to<double>() is incorrect.

Test program:

--8<--
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <locale.h>
#include <langinfo.h>

int main()
{
  double x1 = 987.654;
  boost::multiprecision::number<
    boost::multiprecision::cpp_dec_float<24>,
    boost::multiprecision::et_off> x2 = x1;

  setlocale(LC_NUMERIC, "C");

  std::cout << "radixchar is " << nl_langinfo(RADIXCHAR) << std::endl;
  std::cout << x1 << std::endl;
  std::cout << x2 << std::endl;
  std::cout << x2.convert_to<double>() << std::endl << std::endl;

  setlocale(LC_NUMERIC, "sv_SE.utf8");

  std::cout << "radixchar is " << nl_langinfo(RADIXCHAR) << std::endl;
  std::cout << x1 << std::endl;
  std::cout << x2 << std::endl;
  std::cout << x2.convert_to<double>() << std::endl << std::endl;

  return 0;
}
--8<--

Output:

--8<--
radixchar is .
987.654
987.654
987.654

radixchar is ,
987.654
987.654
9

---8<---

The expected result is the same number is printed in all six cases.

Upstreams issue and fix:

https://github.com/boostorg/multiprecision/issues/464
Comment 1 Marcus Comstedt 2022-07-24 10:16:53 UTC
Created attachment 793847 [details, diff]
Upstreams patch, with filenames modified to match the unified boost dist
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-08-17 18:53:31 UTC
Sorry, I'd meant to apply this earlier, although will likely be sorted w/ 1.80 now.