mtommila/apfloat

ApcomplexMath.w() throws ArithmeticException

Closed this issue · 1 comments

The following code throws an ArithmeticException:

Apfloat re = new Apfloat(1.0);
Apfloat im = new Apfloat(-6.123233995736766e-17);
Apcomplex z = new Apcomplex(re, im);
ApcomplexMath.w(z);

This happens because in the method LambertWHelper.log(Apcomplex z) if the argument of the function is very close to 1, then the value of the logarithm has extremely low precision (in this case only one digit of precision). The subsequent steps of the algorithm then fail as the calculations with only one digit of precision are rather meaningless, and the divisor at one point becomes zero because an intermediate value is rounded to zero due to lack of precision.