pybind / pybind/pybind11

Is there a straightforward way to pass numpy.float128 arguments to C++?

Open
#1,785 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

I'd like to pass an object of type numpy.float128 from Python to a C++ function wrapped by pybind11. My first attempt was to simply use "long double" as argument type on the C++ side, but the values I'm passing are truncated to about "double" accuracy - I expect this happens because the value is cast to a standard Python "float" somewhere on the way.

What would be the proper way to achieve this?

Contributor guide

Open the contributing guide

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.

Research direction

No files, tests, or entry points are named. Start by tracing how pybind11 converts a numpy.float128 argument to a C++ long double, especially where it may become a Python float; done means identifying a supported conversion path or a clearly scoped change that preserves the requested precision.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, numpy, python
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.