2

According to the boost documentation, the boost special functions bessel function (specifically the modified bessel function) should be able to accept a complex input.

However, when I attempt to feed it one, I get a compile error complaining that there is no < operator for operand types float and std::complex<float>.

Here is my code:

using namespace boost::math;    
std::complex<float> cpxTerm = std::complex<float>(m_u1 * cos(az), -wbar * cos(sin(lim)));
std::complex<float> besselTerm = cyl_bessel_i(0, cpxTerm);

As you can see, I'm attempting to use boost's modified bessel function implementation for a 0th order, first-kind modified bessel function.

This returns pages of errors, but as far as I can see, all of them are complaining about the lack of a < operator for the input operands.

I have tried explicitly specifying the template arguments as <int, complex>, <double, complex>, and <complex, complex> to no avail.

Here is one example:

boost.1.50.0/include/boost/math/special_functions/detail/bessel_ik.hpp(108): error: no operator "<" matches these operands
     operand types are: float < std::complex<float>
  d = abs(sigma) < tools::epsilon<T>() ?
                 ^
      detected during:

I'm using the Intel 2013 compiler with C++11 enabled.

What am I doing wrong here?

As a side question, looking at the boost documentation for the function, I noticed this troubling bit:

The functions return the result of domain_error whenever the result is undefined or complex.

Does this mean the function will also fail for complex results when given a complex input (where one would conceivably expect the possibility of a complex output)?

Edit: Digging deeper, it appears the problem is that the std::complex type has no > or < operators. This somewhat makes sense, in that it's somewhat ambiguous to question whether one complex number is greater than the other (does one go by the magnitude, the real component, the imaginary? etc...)

Thus it seems that, although the bessel function is defined for complex inputs, boost itself doesn't support complex inputs for the bessel function. It seems the documentation was a bit misleading on this.

stix
  • 1,140
  • 13
  • 36
  • What is `tools::epsilon()` where `T`==`complex`? As a guess, it is a small `complex`. If so, specialize `tools::epsilon` to return an object that can be compared `<` either the result of `abs(complex)` or `complex` directly. – Yakk - Adam Nevraumont Nov 14 '13 at 15:58
  • Unfortunately that piece of code is in boost itself, so modifying it is a no-go. If the boost documentation is correct (and I think its a reasonable assumption that it is), then the problem should be in how I'm using the function. Unfortunately the problem would be in the three lines of code I posted, which seem reasonable enough. – stix Nov 14 '13 at 16:06
  • 1
    Specializing a traits function for one of your user types is not a no-go. It is probably calling the default implementation, which constructs your complex with a small floating point or double value. – Yakk - Adam Nevraumont Nov 14 '13 at 16:16

0 Answers0