https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121609
Bug ID: 121609
Summary: std::cyl_bessel_j domain error
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: gibelin at unicaen dot fr
Target Milestone: ---
Created attachment 62155
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62155&action=edit
graph result
Dear all,
maybe it is a problem with a missing definition/documentation.
I am trying to used the standard Bessel function:
https://en.cppreference.com/w/cpp/numeric/special_functions/cyl_bessel_j
but I have the following error for 'nu' value lower than zero:
terminate called after throwing an instance of 'std::domain_error'
what(): Bad argument in __cyl_bessel_j.
Aborted (core dumped)
In principle Bessel functions are defined for negative orders:
https://en.wikipedia.org/wiki/Bessel_function
Again, it might be a misunderstand of my part so I tested against other
libraries (boost and gsl here, as well as mapple independently)
#include <cmath>
#include <boost/math/special_functions/bessel.hpp>
#include <gsl/gsl_sf_bessel.h>
#include <iostream>
int main()
{
for(double l = -1.5; l<2;l+=0.5){
for(double x=.1;x<20;x+=.1){
double yboost = boost::math::cyl_bessel_j(l, x);
double ystd = l<0?NAN:std::cyl_bessel_j(l, x);
double ygsl = gsl_sf_bessel_Jnu(l,x);
std::cout << x << " "
<< yboost << " "
<< ystd << " "
<< yboost - ystd << " "
<< ygsl << " "
<< ygsl - ystd << " "
<< "'v=" << l << "'"
<< std::endl;
}
std::cout << std::endl << std::endl ;
}
}
I compiled with:
g++ -Wextra -Wall -fno-strict-aliasing -fwrapv -I/usr/include/ -c bessel_j.C
g++ -Wall -Wextra -fno-strict-aliasing -fwrapv -L/usr/lib/ bessel_j.o -lgsl
-lgslcblas -lm
I had to exclude of course negative orders for std::cyl_bessel_j, the result
in attached file shows that the other numerical values are compatible.
Regards