Page 1 of 1

Increasing Precision with Complex Variables

Posted: Mon Nov 05, 2018 8:45 pm
by REMINGTON30
I have a user-written function that solves for the roots of polynomials. The calculations include complex variables (both real and imaginary parts). The function would benefit from greater than default precision in the floating-point calculations. Setting ⎕FR←1287 often produces a "fatal error" and ends function execution.

Execution time is not an issue in the application considered.

Back in Fortran days, there were double-precision floating point variables and calculations. How does one get increased precision with complex variables in APL?

Re: Increasing Precision with Complex Variables

Posted: Tue Nov 06, 2018 7:26 am
by Morten|Dyalog
⎕FR←645 gives you "double precision", which is the most widely used format for floating-point numbers. A complex number consists of a pair of doubles. ⎕FR←1287 enables the use of a QUADRUPLE precision DECIMAL floating-point representation, which is useful for large financial calculations. However, there is no corresponding quadruple precision complex number format; if you perform a calculation which returns a complex number with ⎕FR set to 1287, you will lose precision and end up with two doubles.

This was simply a "business decision"; we decided that it was not worth the effort to implement QUAD precision complex numbers, as we believed there was essentially no market for them. Your application is the first one I have heard of which requires complex numbers AND more than the 15 digits of precision that DOUBLEs give you.

However, you should NOT be getting "fatal errors"; if you have examples which reproduce this we would be very interested in having the details and fixing what sounds like a bug.

Re: Increasing Precision with Complex Variables

Posted: Wed Nov 07, 2018 10:02 pm
by REMINGTON30
The text file of the code is attached. For test input, the coefficients of the polynomial are

Coeff←3480 ¯11906 16167 ¯11380 4639 ¯1174 193 ¯20 1

The APL code is given in the attached text file. I currently use
Dyalog APL/W-64 Version 17.0.33755
Serial No : 504716
Unicode Edition

Fix the code to the workspace. The function syntax is

PolySolve3 Coeff

⎕FR←645 gives correct results
⎕FR←1287 gives fatal error and exit from APL

Please excuse the somewhat crude code -- I am a beginner.

For the input mentioned, the exact roots are 1 1 2 3 4 5 2J5 2J¯5

Thanks.

Re: Increasing Precision with Complex Variables

Posted: Thu Nov 08, 2018 9:12 am
by AndyS|Dyalog
Looks like that issue was fixed in August.

We'll contact you separately to sort out getting you a fix for this issue.

Re: Increasing Precision with Complex Variables

Posted: Thu Nov 08, 2018 3:04 pm
by REMINGTON30
Thanks. I will apply any updates/patches as soon as possible.