Multiprecision Python library that plays well with boost::multiprecision or other options?

我的梦境 提交于 2019-12-11 13:14:07

问题


I am working on a project that revolves around multiprecision "complex" numbers, specifically it's a Mandelbrot Set-based app, but with a twist that requires decent correspondence between the output of a (fast) C++ py extension module (boost, cython, or other...) and the pure python modules that might want to use it.

Right now, I'm using boost::multiprecision to wrap the MPFR raw type, and yeah if I just wanted to pass an mpfr_t to python that'd be one thing. However, for this app I need to store the C++ module's result as a string which will be interpreted later by a Python module, and needs to give the same number.

BigFloat is supposed to be an MPFR python wrapper, but it doesn't interpret a string literal of an X-precision float exactly the same way as boost::multiprecision's data() method.

Does anybody know of a combination of libraries plus an approach that does result in an exact correspondence between C++ and Python string literals of arbitrary-precision floating-point numbers?

I can provide code excerpts if needed to illustrate the problem, but figured it was arcane enough that if anybody had the answer, they'd know exactly what I mean and how to fix it.


回答1:


I maintain gmpy2 which is a Python wrapper for both MPFR and MPC (and GMP). If you can provide an example, I may be able to help.



来源:https://stackoverflow.com/questions/16369616/multiprecision-python-library-that-plays-well-with-boostmultiprecision-or-othe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!