boostorg / boostorg/multiprecision

Initializing multiprecision types in `std::array`s

Open
#188 7 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
265
Forks
128
Avg merge
4h 48m
Merged PRs (30d)
2

Description

In the following code:

```
#include
#include

using boost::multiprecision::cpp_bin_float_oct;
int main() {
std::array a{"0.482962913144534143374871599864448683816952419504202275201171538155211606550",
"0.836516303737807905575293780916873203459370388348439293495341472652894725147",
"0.224143868042013381025972762240400355467883518184271761387168330840154631777",
"-0.129409522551260381174449418812024164174534450659965256907001603657528486820"};

cpp_bin_float_oct b{"0.482962913144534143374871599864448683816952419504202275201171538155211606550"};
std::cout << b << "\n";

}
```

There is no problem initializing `b`, but initializing `a` causes a problem:

```
oct_test.cpp:6:40: error: could not convert '"0.482962913144534143374871599864448683816952419504202275201171538155211606550"' from 'const char [78]' to 'boost::multiprecision::number, boost::multiprecision::et_off>'
6 | std::array a{"0.482962913144534143374871599864448683816952419504202275201171538155211606550",
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| |
| const char [78]
compilation terminated due to -Wfatal-errors.
```

What is the best way to initialize a `std::array` with multiprecision types?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the minimal example in the issue and compare direct initialization of cpp_bin_float_oct with initialization through std::array. Investigate the relevant Boost.Multiprecision and standard-library initialization behavior, then determine and document a supported way to initialize the array or confirm that the behavior needs a library change.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.