Skip to content
Snippets Groups Projects
Commit dbc441d4 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

remove special handling of NaNs in complex multiplication

parent 1bd47865
Branches
No related tags found
No related merge requests found
......@@ -258,12 +258,10 @@ public abstract class BinaryArithmetic extends Operation {
double[] res = new double[2];
double[] interm = new double[4];
complexMult(leftReal, leftImag, rightReal, rightImag, res, interm);
if (Double.isNaN(res[0]) && Double.isNaN(res[1])) {
CompilerDirectives.transferToInterpreterAndInvalidate();
MultiplyNaN multNaN = new MultiplyNaN();
replace(multNaN);
return multNaN.handleNaN(leftReal, leftImag, rightReal, rightImag, res, interm);
}
/*
* LStadler: removed the special code for handling NaNs in the result, since it works
* fine (and the tests are broken either way). to revive it, get it from the history.
*/
return RDataFactory.createComplex(res[0], res[1]);
}
......@@ -297,59 +295,6 @@ public abstract class BinaryArithmetic extends Operation {
}
private static final class MultiplyNaN extends Multiply {
private final ConditionProfile inf1 = ConditionProfile.createBinaryProfile();
private final ConditionProfile inf2 = ConditionProfile.createBinaryProfile();
private final ConditionProfile inf3 = ConditionProfile.createBinaryProfile();
@Override
public RComplex op(double leftReal, double leftImag, double rightReal, double rightImag) {
double[] res = new double[2];
double[] interm = new double[4];
complexMult(leftReal, leftImag, rightReal, rightImag, res, interm);
if (Double.isNaN(res[0]) && Double.isNaN(res[1])) {
return handleNaN(leftReal, leftImag, rightReal, rightImag, res, interm);
}
return RDataFactory.createComplex(res[0], res[1]);
}
protected RComplex handleNaN(double leftReal, double leftImag, double rightReal, double rightImag, double[] res, double[] interm) {
boolean recalc = false;
double ra = leftReal;
double rb = leftImag;
double rc = rightReal;
double rd = rightImag;
if (inf1.profile(Double.isInfinite(ra) || Double.isInfinite(rb))) {
ra = convertInf(ra);
rb = convertInf(rb);
rc = convertNaN(rc);
rd = convertNaN(rd);
recalc = true;
}
if (inf2.profile(Double.isInfinite(rc) || Double.isInfinite(rd))) {
rc = convertInf(rc);
rd = convertInf(rd);
ra = convertNaN(ra);
rb = convertNaN(rb);
recalc = true;
}
if (inf3.profile(!recalc && (Double.isInfinite(interm[0]) || Double.isInfinite(interm[1]) || Double.isInfinite(interm[2]) || Double.isInfinite(interm[3])))) {
ra = convertNaN(ra);
rb = convertNaN(rb);
rc = convertNaN(rc);
rd = convertNaN(rd);
recalc = true;
}
if (recalc) {
res[0] = Double.POSITIVE_INFINITY * (ra * rc - rb * rd);
res[1] = Double.POSITIVE_INFINITY * (ra * rd + rb * rc);
}
return RDataFactory.createComplex(res[0], res[1]);
}
}
private static class Div extends BinaryArithmetic {
public Div() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment