Boost multiprecision fails because the implementation of complex tries to cast to double in internal functions like _Isinf or _Isnan

♀尐吖头ヾ 提交于 2019-12-23 09:58:13

问题


I need a BSD-like licensed C(++) multiprecision library with complex numbers support so I tried boost.

The following code fails:

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <complex>

using namespace boost::multiprecision;    
std::complex<cpp_dec_float_50>(1.0, 2.0) / std::complex<cpp_dec_float_50>(1.0, 2.0)

in Visual Studio 2012 with an error C2440 because the implementation of complex tries to cast to double in internal functions like _Isinf or _Isnan.

Is this an error on my part? How can I fix this? Are there better libraries?


回答1:


From C++11 26.4/2:

The effect of instantiating the template complex for any type other than float, double, or long double is unspecified.

So you can't reliably use std::complex with other types, but perhaps boost has a complex type that works with cpp_dec_float_50.




回答2:


GCC 4.7 will allow you to use boost multiprecision floats with std::complex<>.



来源:https://stackoverflow.com/questions/16861798/boost-multiprecision-fails-because-the-implementation-of-complex-tries-to-cast-t

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