From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:4c89:: with SMTP id j9mr19316298qtv.326.1590967531625; Sun, 31 May 2020 16:25:31 -0700 (PDT) X-Received: by 2002:a4a:a785:: with SMTP id l5mr2101704oom.74.1590967531404; Sun, 31 May 2020 16:25:31 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sun, 31 May 2020 16:25:31 -0700 (PDT) In-Reply-To: <45af26dc-c35f-4a01-8115-7b30021cc064@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: google-groups.googlegroups.com; posting-host=97.124.214.243; posting-account=x5rpZwoAAABMN2XPwcebPWPkebpwQNJG NNTP-Posting-Host: 97.124.214.243 References: <45af26dc-c35f-4a01-8115-7b30021cc064@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Any good package for mathematical function in Ada? From: Jerry Injection-Date: Sun, 31 May 2020 23:25:31 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:58908 Date: 2020-05-31T16:25:31-07:00 List-Id: On Sunday, May 31, 2020 at 3:46:47 AM UTC-7, reinert wrote: > Hello, >=20 > I would like to use for example the bessel function from Ada. > I need in case to program it from scratch? >=20 > Any hint? >=20 > reinert You have hit on what, for me, is a PITA for Ada, generally speaking, and th= at is a lack of broad numerical functions. You can link to the GNU Scientific Library (GSL) or the Octave binary libra= ry (I have also once written a very simple special-case Octave code generat= or to run interpreter code since some functionality is not available as com= piled code). You might also enjoy ALGLIB, IMSL, NAG, and NetLib depending o= n the licenses. You might be able to link to the Python libraries scipy and= numpy if, as I _suppose_ ,they are written in C. Consult this list if you = like:=20 https://en.wikipedia.org/wiki/List_of_numerical_libraries BTW if you have access to Numerical Recipes it can be a lifesaver sometimes= . I have an early book with Pascal code in an appendix. If the binary you are linking to is in C or Fortran your job as an Ada prog= rammer isn't too bad but if you have never done it, it will take you a whil= e to figure it out. Just remember that Ada is built to do this. I did a com= plete thick binding for PLplot a few years ago. It was lot of work to make = it Ada-friendly but in large part because I didn't know C. And in a smaller= part because it seems that programming in a crappy language spawns crappy = programming techniques. Some of the things C programmers do are abominable = and not required by the language. Sorry for the OT rant. I just remembered that I did this (Bessel) for GSL--I'm on a Mac and I got = GSL via MacPorts. Note well that you don't have to link to the whole librar= y, only the function(s) that you need. I'll paste the Ada with my comments = which might be superfluous for you, and a gpr file as well; the gpr is incl= uded in a larger gpr. I really wish Ada had a good binding to at least one of these libraries. Jerry library project GSL_Library is for Externally_Built use "true"; for Library_Dir use "/opt/local/lib/"; for Library_Name use "gsl"; -- Delete "lib" from front of file name, .d= ylib from end. for Library_Kind use "dynamic"; end GSL_Library; -- Partial Ada binding to the GNU Scientific Library aka GSL library, libgs= l.dylib. -- See http://www.gnu.org/software/gsl/. -- Use $nm library_name | grep symbol_name to find if symbol_name is in a l= ibrary. -- This binding will be developed as needed. See build.gpr and GSL_Library.= gpr. -- Consider this binding as an adjunct to e.g. Octave binding and Numerical= Recipes. package GSL_Thin is =20 -----------------------------------------------------------------------= ---- -- CHAPTER 7: SPECIAL FUNCTIONS = -- -----------------------------------------------------------------------= ---- =20 -- See GSL Reference 7.3 about modes. _Apparently_ double precision is = the default and no -- mode flag (argument) is necessary. The Reference could be less ambig= uous about this. -- Regular cylindrical Bessel function of zeroth order, J_0(x). function gsl_sf_bessel_J0(x : Long_Float) return Long_Float; pragma Import(C, gsl_sf_bessel_J0, "gsl_sf_bessel_J0"); =20 -- Complete elliptical integral of the first kind, K(k). GSL Reference = 7.13.3. -- Mathematica EllipticK and Abramowitz & Stegun 17.3 use argument m = =3D k^2. -- As far as I can tell, this returns correct results only for 0 < k < = 1, and then only if -- sqrt(k) is given as the argument. I have contacted the list (April, = 2015) about this and got -- no response. I am using this for the PDF of the sum of two unit-ampl= itude sine random -- variables where this limitation is not a problem. Otherwise, I don't= see how to use this to -- get results such as returned by A&S or Octave. (The Octave function = is coded as Octave code, -- not a compiled library.) function gsl_sf_ellint_Kcomp(k : Long_Float) return Long_Float; pragma Import(C, gsl_sf_ellint_Kcomp, "gsl_sf_ellint_Kcomp"); =20 end GSL_Thin;