complex_result_from_scalar for the built-in floating-point types

Open
#779 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
cpp
Domain
backend

Research direction

Start by locating complex_result_from_scalar and its existing multiprecision specializations in Boost.Multiprecision, then check how nearby traits and tests are organized. Add the built-in floating-point mappings proposed in the issue and verify the trait resolves to the matching std::complex type for float, double and long double; the issue does not name a test file.

Written by the indexing model from the issue text.

Description

complex_result_from_scalar<T> maps a multiprecision real type to its complex counterpart (cpp_bin_float_50 to cpp_complex_50, mpfr_float to mpc_complex, ...), but the primary template is left undefined, so it has no answer for the built-in types:

boost::multiprecision::complex_result_from_scalar<double>::type   // error: incomplete type

Generic code that works for both, like Boost.Math's FFT, Chebyshev transform and polynomial root finders, therefore needs a second trait for the built-in half. Boost.Math currently carries one, tools::detail::complex_from_real, which picks std::complex<Real> for float, double and long double and forwards everything else to complex_result_from_scalar.

Could Multiprecision provide it instead?

template <> struct complex_result_from_scalar<float>       { using type = std::complex<float>; };
template <> struct complex_result_from_scalar<double>      { using type = std::complex<double>; };
template <> struct complex_result_from_scalar<long double> { using type = std::complex<long double>; };

template <class T>
using complex_result_from_scalar_t = typename complex_result_from_scalar<T>::type;

The primary template is currently incomplete, so these specialisations can't change the meaning of any code that compiles today. Boost.Math would then drop complex_from_real and use the Multiprecision trait directly.

🤖 Generated with Claude Code

Dominant language
C++
Stars
268
Forks
130
Avg merge
1d 15h
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/multiprecision

All issues in boostorg/multiprecision

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.