1
$\begingroup$

I am new to Wolfram Language and wolfram engine. I use wolfram engine development kit to increase the precision of the output from Spherical Bessel function from WSTP in c++. Part of codes that transfer functions and parameters to the link is

int order = 1;
long double x = 15;
long double result;
WSPutFunction( lp, "N", 2);
    WSPutFunction( lp, "SphericalBesselY", 2);
        WSPutInteger( lp, order);
            WSPutReal128(lp, x);
                WSPutInteger(lp, 30);
 WSEndPacket( lp);
 WSGetReal128( lp, &result);
    printf( "%.30Lf \n ", result);

However, whatever precision number I alter, the result is the same and

$\endgroup$
5
  • 1
    $\begingroup$ (1) N[SphericalBesselY[2, x], 30] will return a machine-precision number if x is machine precision. I have not tried quad-precision numbers, but probably it is either unsupported or N[..] returns a quad-precision number. For your N[..] call to work, the input x should be exact or of a high-enough precision that SphericalBesselY evalutes to at least 30 digits of precision.... $\endgroup$
    – Michael E2
    Jul 16, 2020 at 13:16
  • 2
    $\begingroup$ (2) From the docs: "Note that you can conveniently exchange arbitrary-precision numbers with external programs by converting them to lists of digits in the Wolfram Language using IntegerDigits and RealDigits." It appears you're trying to read a quad-precision FP number, not an arbitrary-precision number. If N[..] works as you seem to intend, it should return an arbitrary-precision number. $\endgroup$
    – Michael E2
    Jul 16, 2020 at 13:18
  • $\begingroup$ I guess I should add (3) your question ends mid sentence. $\endgroup$
    – Michael E2
    Jul 16, 2020 at 13:19
  • 1
    $\begingroup$ Okay, my first two comments may be wrong if Real128 is supported as it is in Import/Export. Nonetheless, N[expr, prec] cannot be used to raise the precision. Also N[y, newprec] might not change the underlying point-estimate used to compute the Real128 number (if quad behaves like double). E.g. N of the Real128 value of E is N[2.718281828459045235360287471352662314358421867194`33.71535951436589, 30] resulting in 2.718281828459045235360287471352662314358421867194`30., which has exactly the same numerical value. $\endgroup$
    – Michael E2
    Jul 16, 2020 at 13:35
  • $\begingroup$ thanks, my question then should be directed to how to change the a machine precision digits into arbitrary precision digit and parse to link within WSTP. @MichaelE2 $\endgroup$
    – Wasabi
    Jul 16, 2020 at 21:35

1 Answer 1

1
$\begingroup$

You're feeding it with the same precision so it's hard to expect different results, I think.

In Mathematica itself:

SphericalBesselY[1, 15.] // Accuracy

will give you 17.35 [decimal] digits of accuracy. I'm not sure how WSTP treats 128bit floating numbers though

By contrast:

SphericalBesselY[1, 15.] (* -0.0399761*)
SphericalBesselY[1,15`100] (* telling it 15 is precise up to 100 digits will answer -0.0399761319533241409493242562719989970404441275224595705839764978076\
671781562996219519312380539715616 *)

So the problems seems to be with passing arbitrary precision numbers over WSTP.

Probably someone can suggest how to do it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.