Example usage for java.lang Double isInfinite

List of usage examples for java.lang Double isInfinite

Introduction

In this page you can find the example usage for java.lang Double isInfinite.

Prototype

public static boolean isInfinite(double v) 

Source Link

Document

Returns true if the specified number is infinitely large in magnitude, false otherwise.

Usage

From source file:org.apache.noggit.ObjectBuilder.java

public Object getNumber() throws IOException {
        CharArr num = parser.getNumberChars();
        String numstr = num.toString();
        double d = Double.parseDouble(numstr);
        if (!Double.isInfinite(d))
            return Double.valueOf(d);
        // TODO: use more efficient constructor in Java5
        return new BigDecimal(numstr);
    }// w w w  .  ja v  a2 s. c  om

From source file:org.deeplearning4j.plot.LegacyTsne.java

/**
 * Convert data to probability//from w w  w  . j a  v a2s  . c om
 * co-occurrences (aka calculating the kernel)
 * @param d the data to convert
 * @param u the perplexity of the model
 * @return the probabilities of co-occurrence
 */
public INDArray computeGaussianPerplexity(final INDArray d, double u) {
    int n = d.rows();
    final INDArray p = zeros(n, n);
    final INDArray beta = ones(n, 1);
    final double logU = Math.log(u);

    log.info("Calculating probabilities of data similarities..");
    for (int i = 0; i < n; i++) {
        if (i % 500 == 0 && i > 0)
            log.info("Handled " + i + " records");

        double betaMin = Double.NEGATIVE_INFINITY;
        double betaMax = Double.POSITIVE_INFINITY;
        int[] vals = Ints.concat(ArrayUtil.range(0, i), ArrayUtil.range(i + 1, d.columns()));
        INDArrayIndex[] range = new INDArrayIndex[] { new SpecifiedIndex(vals) };

        INDArray row = d.slice(i).get(range);
        Pair<INDArray, INDArray> pair = hBeta(row, beta.getDouble(i));
        INDArray hDiff = pair.getFirst().sub(logU);
        int tries = 0;

        //while hdiff > tolerance
        while (BooleanIndexing.and(abs(hDiff), Conditions.greaterThan(tolerance)) && tries < 50) {
            //if hdiff > 0
            if (BooleanIndexing.and(hDiff, Conditions.greaterThan(0))) {
                if (Double.isInfinite(betaMax))
                    beta.putScalar(i, beta.getDouble(i) * 2.0);
                else
                    beta.putScalar(i, (beta.getDouble(i) + betaMax) / 2.0);
                betaMin = beta.getDouble(i);
            } else {
                if (Double.isInfinite(betaMin))
                    beta.putScalar(i, beta.getDouble(i) / 2.0);
                else
                    beta.putScalar(i, (beta.getDouble(i) + betaMin) / 2.0);
                betaMax = beta.getDouble(i);
            }

            pair = hBeta(row, beta.getDouble(i));
            hDiff = pair.getFirst().subi(logU);
            tries++;
        }

        p.slice(i).put(range, pair.getSecond());

    }

    //dont need data in memory after
    log.info("Mean value of sigma " + sqrt(beta.rdiv(1)).mean(Integer.MAX_VALUE));
    BooleanIndexing.applyWhere(p, Conditions.isNan(), new Value(realMin));

    //set 0 along the diagonal
    INDArray permute = p.transpose();

    INDArray pOut = p.add(permute);

    pOut.divi(pOut.sum(Integer.MAX_VALUE));
    BooleanIndexing.applyWhere(pOut, Conditions.lessThan(Nd4j.EPS_THRESHOLD), new Value(Nd4j.EPS_THRESHOLD));
    //ensure no nans
    return pOut;

}

From source file:org.jtrfp.trcl.obj.TunnelSegment.java

private static Model createModel(Segment s, double segLen, TextureDescription[] tunnelTexturePalette,
        double endX, double endY, final TR tr) {
    Model mainModel = new Model(true, tr);
    mainModel.setDebugName("tunnelSegment main.");
    final int numPolys = s.getNumPolygons();
    double startWidth = getStartWidth(s);
    double startHeight = getStartHeight(s);
    double endWidth = getEndWidth(s);
    double endHeight = getEndHeight(s);
    final FlickerLightType lightType = s.getFlickerLightType();
    // TODO: Cleanup.
    final double startAngle1 = ((double) s.getStartAngle1() / 65535.) * 2. * Math.PI;
    final double startAngle2 = ((double) s.getStartAngle2() / 65535.) * 2. * Math.PI;
    final double startAngle = startAngle1;
    final double endAngle1 = ((double) s.getEndAngle1() / 65535.) * 2. * Math.PI;
    final double endAngle2 = ((double) s.getEndAngle2() / 65535.) * 2. * Math.PI;
    double endAngle = endAngle1;
    final double dAngleStart = (startAngle2 - startAngle1) / (double) numPolys;
    final double dAngleEnd = (endAngle2 - endAngle1) / (double) numPolys;
    final double startX = 0;
    final double startY = 0;
    final double zStart = 0;
    final double zEnd = segLen;
    final int numPolygonsMinusOne = s.getNumPolygons() - 1;
    final int lightPoly = s.getLightPolygon();
    final boolean hasLight = lightPoly != -1;
    if (hasLight) {
        mainModel.setAnimateUV(true);/*from  www .j  a v a2s  .  c  o  m*/
        mainModel.setSmoothAnimation(false);
        if (lightType == FlickerLightType.noLight) {
            //Do nothing.
        } else if (lightType == FlickerLightType.off1p5Sec) {
            mainModel.setController(new Controller() {
                private final int off = (int) (Math.random() * 2000);

                @Override
                public double getCurrentFrame() {
                    return (off + System.currentTimeMillis() % 2000) > 1500 ? 1 : 0;
                }

                @Override
                public void setDebugMode(boolean b) {
                    //Not implemented.
                }
            });
        } else if (lightType == FlickerLightType.on1p5Sec) {
            mainModel.setController(new Controller() {
                private final int off = (int) (Math.random() * 2000);

                @Override
                public double getCurrentFrame() {
                    return (off + System.currentTimeMillis() % 2000) < 1500 ? 1 : 0;
                }

                @Override
                public void setDebugMode(boolean b) {
                    //Not implemented.
                }
            });
        } else if (lightType == FlickerLightType.on1Sec) {
            mainModel.setController(new Controller() {
                private final int off = (int) (Math.random() * 2000);

                @Override
                public double getCurrentFrame() {
                    return (off + System.currentTimeMillis() % 2000) > 1000 ? 1 : 0;
                }

                @Override
                public void setDebugMode(boolean b) {
                    //Not implemented.
                }
            });
        }
    } //end (has light)
    final double[] noLightU = new double[] { 1, 1, 0, 0 };
    final double[] noLightV = new double[] { 0, 1, 1, 0 };
    final double[] lightOffU = new double[] { 1, 1, .5, .5 };
    final double[] lightOffV = new double[] { .5, 1, 1, .5 };
    final double[] lightOnU = new double[] { .5, .5, 0, 0 };
    final double[] lightOnV = new double[] { .5, 1, 1, .5 };

    double rotPeriod = (1000. * 32768.) / (double) s.getRotationSpeed();
    final boolean reverseDirection = rotPeriod < 0;
    if (reverseDirection)
        rotPeriod *= -1;
    final int numFramesIfRotating = 30;
    final int numFramesIfStatic = 2;
    final boolean isRotating = !Double.isInfinite(rotPeriod);
    int numAnimFrames = isRotating ? numFramesIfRotating : numFramesIfStatic;
    if (isRotating)
        mainModel.setFrameDelayInMillis((int) (rotPeriod / (numAnimFrames)));
    final double animationDeltaRadians = isRotating
            ? ((reverseDirection ? 1 : -1) * (2 * Math.PI) / (double) numAnimFrames)
            : 0;
    //FRAME LOOP
    for (int frameIndex = 0; frameIndex < numAnimFrames; frameIndex++) {
        final Model m = new Model(false, tr);
        m.setDebugName("TunnelSegment frame " + frameIndex + " of " + numAnimFrames);
        final double frameAngleDeltaRadians = animationDeltaRadians * (double) frameIndex;
        double frameStartAngle = startAngle + frameAngleDeltaRadians;
        double frameEndAngle = endAngle + frameAngleDeltaRadians;
        final double frameStartAngle1 = startAngle1 + frameAngleDeltaRadians;
        final double frameStartAngle2 = startAngle2 + frameAngleDeltaRadians;
        final double frameEndAngle1 = endAngle + frameAngleDeltaRadians;
        double[] thisU = noLightU, thisV = noLightV;//Changeable u/v references, default to noLight
        // Poly quads
        for (int pi = 0; pi < numPolygonsMinusOne; pi++) {
            Vector3D p0 = segPoint(frameStartAngle, zStart, startWidth, startHeight, startX, startY);
            Vector3D p1 = segPoint(frameEndAngle, zEnd, endWidth, endHeight, endX, endY);
            Vector3D p2 = segPoint(frameEndAngle + dAngleEnd, zEnd, endWidth, endHeight, endX, endY);
            Vector3D p3 = segPoint(frameStartAngle + dAngleStart, zStart, startWidth, startHeight, startX,
                    startY);

            TextureDescription tex = tunnelTexturePalette[s.getPolyTextureIndices().get(pi)];

            if (pi == lightPoly && lightType != FlickerLightType.noLight) {
                if (frameIndex == 0) {
                    thisU = lightOnU;
                    thisV = lightOnV;
                } else {
                    thisU = lightOffU;
                    thisV = lightOffV;
                }
                /*try {
                            
                    final int flickerThresh = flt == FlickerLightType.off1p5Sec ? (int) (-.3 * (double) Integer.MAX_VALUE)
                       : flt == FlickerLightType.on1p5Sec ? (int) (.4 * (double) Integer.MAX_VALUE)
                          : flt == FlickerLightType.on1Sec ? (int) (.25 * (double) Integer.MAX_VALUE)
                             : Integer.MAX_VALUE;
                        
                    m.addTickableAnimator(new Tickable() {
                   @Override
                   public void tick() {
                       if (flickerRandom.transfer(Math.abs((int) System
                          .currentTimeMillis())) > flickerThresh)
                      st.setFrame(1);
                       else
                      st.setFrame(0);
                   }
                           
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                }*/
            } else {
                thisU = noLightU;
                thisV = noLightV;
            } // No light

            m.addTriangles(Triangle.quad2Triangles(new double[] { p3.getX(), p2.getX(), p1.getX(), p0.getX() },
                    new double[] { p3.getY(), p2.getY(), p1.getY(), p0.getY() },
                    new double[] { p3.getZ(), p2.getZ(), p1.getZ(), p0.getZ() }, thisU, thisV, tex,
                    RenderMode.DYNAMIC,
                    new Vector3D[] {
                            new Vector3D(Math.cos(frameStartAngle + dAngleStart),
                                    -Math.sin(frameStartAngle + dAngleStart), 0),
                            new Vector3D(Math.cos(frameEndAngle + dAngleEnd),
                                    -Math.sin(frameEndAngle + dAngleEnd), 0),
                            new Vector3D(Math.cos(frameEndAngle), -Math.sin(frameEndAngle), 0),
                            new Vector3D(Math.cos(frameStartAngle), -Math.sin(frameStartAngle), 0) },
                    0));
            frameStartAngle += dAngleStart;
            frameEndAngle += dAngleEnd;
        } // for(polygons)
        if (s.isCutout()) {
            // The slice quad
            // INWARD
            Vector3D p0 = segPoint(frameStartAngle, zStart, startWidth, startHeight, startX, startY);
            Vector3D p1 = segPoint(frameEndAngle, zEnd, endWidth, endHeight, endX, endY);
            Vector3D p2 = segPoint(frameEndAngle1, zEnd, 0, 0, endX, endY);
            Vector3D p3 = segPoint(frameStartAngle1, zStart, 0, 0, startX, startY);
            m.addTriangles(Triangle.quad2Triangles(new double[] { p3.getX(), p2.getX(), p1.getX(), p0.getX() },
                    new double[] { p3.getY(), p2.getY(), p1.getY(), p0.getY() },
                    new double[] { p3.getZ(), p2.getZ(), p1.getZ(), p0.getZ() },

                    new double[] { 1, 1, 0, 0 }, new double[] { 0, 1, 1, 0 },
                    tunnelTexturePalette[s.getPolyTextureIndices().get(numPolygonsMinusOne)],
                    RenderMode.DYNAMIC,
                    new Vector3D[] {
                            new Vector3D(Math.cos(frameStartAngle + dAngleStart),
                                    -Math.sin(frameStartAngle + dAngleStart), 0),
                            new Vector3D(Math.cos(frameEndAngle + dAngleEnd),
                                    -Math.sin(frameEndAngle + dAngleEnd), 0),
                            new Vector3D(Math.cos(frameEndAngle), -Math.sin(frameEndAngle), 0),
                            new Vector3D(Math.cos(frameStartAngle), -Math.sin(frameStartAngle), 0) },
                    0));
            // OUTWARD
            p3 = segPoint(frameStartAngle1, zStart, startWidth, startHeight, startX, startY);
            p2 = segPoint(frameEndAngle1, zEnd, endWidth, endHeight, endX, endY);
            p1 = segPoint(frameEndAngle1, zEnd, 0, 0, endX, endY);
            p0 = segPoint(frameStartAngle1, zStart, 0, 0, startX, startY);
            m.addTriangles(Triangle.quad2Triangles(new double[] { p3.getX(), p2.getX(), p1.getX(), p0.getX() },
                    new double[] { p3.getY(), p2.getY(), p1.getY(), p0.getY() },
                    new double[] { p3.getZ(), p2.getZ(), p1.getZ(), p0.getZ() },

                    new double[] { 1, 1, 0, 0 }, new double[] { 0, 1, 1, 0 },
                    tunnelTexturePalette[s.getPolyTextureIndices().get(numPolygonsMinusOne)],
                    RenderMode.DYNAMIC,
                    new Vector3D[] {
                            new Vector3D(Math.cos(frameStartAngle + dAngleStart),
                                    -Math.sin(frameStartAngle + dAngleStart), 0),
                            new Vector3D(Math.cos(frameEndAngle + dAngleEnd),
                                    -Math.sin(frameEndAngle + dAngleEnd), 0),
                            new Vector3D(Math.cos(frameEndAngle), -Math.sin(frameEndAngle), 0),
                            new Vector3D(Math.cos(frameStartAngle), -Math.sin(frameStartAngle), 0) },
                    0));
        } else {
            // The slice quad
            Vector3D p0 = segPoint(frameStartAngle, zStart, startWidth, startHeight, startX, startY);
            Vector3D p1 = segPoint(frameEndAngle, zEnd, endWidth, endHeight, endX, endY);
            Vector3D p2 = segPoint(frameEndAngle1, zEnd, endWidth, endHeight, endX, endY);
            Vector3D p3 = segPoint(frameStartAngle1, zStart, startWidth, startHeight, startX, startY);
            m.addTriangles(Triangle.quad2Triangles(new double[] { p3.getX(), p2.getX(), p1.getX(), p0.getX() },
                    new double[] { p3.getY(), p2.getY(), p1.getY(), p0.getY() },
                    new double[] { p3.getZ(), p2.getZ(), p1.getZ(), p0.getZ() },

                    new double[] { 1, 1, 0, 0 }, new double[] { 0, 1, 1, 0 },
                    tunnelTexturePalette[s.getPolyTextureIndices().get(numPolygonsMinusOne)],
                    RenderMode.DYNAMIC,
                    new Vector3D[] {
                            new Vector3D(Math.cos(frameStartAngle + dAngleStart),
                                    -Math.sin(frameStartAngle + dAngleStart), 0),
                            new Vector3D(Math.cos(frameEndAngle + dAngleEnd),
                                    -Math.sin(frameEndAngle + dAngleEnd), 0),
                            new Vector3D(Math.cos(frameEndAngle), -Math.sin(frameEndAngle), 0),
                            new Vector3D(Math.cos(frameStartAngle), -Math.sin(frameStartAngle), 0) },
                    0));
        } //end !cutout
          //if(numAnimFrames!=1)//Push frame if animated.
        mainModel.addFrame(m);
    } //end for(frames)
    return mainModel;
}

From source file:com.opengamma.analytics.math.interpolation.MonotoneConvexSplineInterpolator.java

@Override
public double interpolate(final double[] xValues, final double[] yValues, final double x) {

    final PiecewisePolynomialResult result = interpolate(xValues, yValues);
    final DoubleMatrix2D coefsMatrixIntegrate = result.getCoefMatrix();
    final int nKnots = coefsMatrixIntegrate.getNumberOfRows() + 1;
    final double[] knots = result.getKnots().getData();

    int indicator = 0;
    if (x <= knots[1]) {
        indicator = 0;/*from   w w w.j a v  a2  s. c o  m*/
    } else {
        for (int i = 1; i < nKnots - 1; ++i) {
            if (knots[i] < x) {
                indicator = i;
            }
        }
    }

    final double[] coefs = coefsMatrixIntegrate.getRowVector(indicator).getData();

    final double res = getValue(coefs, x, knots[indicator]);
    ArgumentChecker.isFalse(Double.isInfinite(res), "Too large/small data values or xKey");
    ArgumentChecker.isFalse(Double.isNaN(res), "Too large/small data values or xKey");

    return res;
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.particlefilter.ParticleFilter.java

public static double getEffectiveSampleSize(Multiset<Particle> particles)
        throws BadProbabilityParticleFilterException {
    double Wnorm = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wnorm += weight * p.getCount();/*from   ww  w. j a va  2s. c  o  m*/
    }

    if (Wnorm == 0)
        return 0d;

    double Wvar = 0.0;
    for (final Multiset.Entry<Particle> p : particles.entrySet()) {
        final double weight = p.getElement().getWeight();
        Wvar += FastMath.pow(weight / Wnorm, 2) * p.getCount();
    }

    if (Double.isInfinite(Wvar) || Double.isNaN(Wvar))
        throw new BadProbabilityParticleFilterException("effective sample size numerical error: Wvar=" + Wvar);

    return 1 / Wvar;
}

From source file:org.geoserver.wms.map.QuickTileCache.java

/**
 * This is tricky. We need to have doubles that can be compared by equality because resolution
 * and origin are doubles, and are part of a hashmap key, so we have to normalize them somehow,
 * in order to make the little differences disappear. Here we take the mantissa, which is made
 * of 52 bits, and throw away the 20 more significant ones, which means we're dealing with 12
 * significant decimal digits (2^40 -> more or less one billion million). See also <a
 * href="http://en.wikipedia.org/wiki/IEEE_754">IEEE 754</a> on Wikipedia.
 * /*from ww w  .  jav  a2 s  . c om*/
 * @param d
 * @return
 */
static double normalize(double d) {
    if (Double.isInfinite(d) || Double.isNaN(d)) {
        return d;
    }

    return Math.round(d * 10e6) / 10e6;
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Update the {@link HrDiagram#hrDiagPanel}.
 *///from   w w  w. j  av a  2  s  . c om
private void updateChart() {

    XYSeries series = new XYSeries("TGAS HR diagram");

    // Count the stars
    int n = 0;

    for (TgasStar tgasStar : tgasStars) {

        // Get the TGAS magnitude and colour indices
        double g = tgasStar.phot_g_mean_mag;
        double bv = tgasStar.bt_mag - tgasStar.vt_mag;

        // Use the parallax to correct the apparent magnitude to absolute magnitude.

        // Extract the parallax and error to use
        double p = tgasStar.parallax;
        double sigma_p = tgasStar.parallax_error;

        // Filter on the fractional parallax error
        double f = sigma_p / Math.abs(p);
        if (f > fMax) {
            continue;
        }

        // Filter out objects with no B-V index
        if (bv == 0.0) {
            continue;
        }

        // Correct to arcseconds
        p /= 1000;
        sigma_p /= 1000;

        // Get the distance
        double d = DistanceFromParallax.getDistance(p, sigma_p, method);

        // Filter & convert to absolute magnitude
        if (d > 0 && !Double.isInfinite(d)) {

            n++;

            double G = MagnitudeUtils.getAbsoluteMagnitude(d, g);
            series.add(bv, G);
        }
    }

    logger.log(Level.INFO, "Plotting " + n + " Hipparcos stars.");

    JFreeChart hrChart = getHrChart(series);
    if (hrDiagPanel == null) {
        // Branch is used on initialisation
        hrDiagPanel = new ChartPanel(hrChart);
    } else {
        hrDiagPanel.setChart(hrChart);
    }
}

From source file:com.joptimizer.util.MPSParser.java

public MPSParser(double unspecifiedLBValue, double unspecifiedUBValue, double unboundedLBValue,
        double unboundedUBValue) {
    if (!Double.isNaN(unboundedLBValue) && !Double.isInfinite(unboundedLBValue)) {
        throw new IllegalArgumentException(
                "The field unboundedLBValue must be set to Double.NaN or Double.NEGATIVE_INFINITY");
    }//from w ww. j ava2 s. c om
    if (!Double.isNaN(unboundedUBValue) && !Double.isInfinite(unboundedUBValue)) {
        throw new IllegalArgumentException(
                "The field unboundedUBValue must be set to Double.NaN or Double.POSITIVE_INFINITY");
    }
    this.unspecifiedLBValue = unspecifiedLBValue;
    this.unspecifiedUBValue = unspecifiedUBValue;
    this.unboundedLBValue = unboundedLBValue;
    this.unboundedUBValue = unboundedUBValue;
}

From source file:com.clust4j.algo.NearestNeighborHeapSearch.java

/**
 * Constructor with logger object//from   w w w .ja va 2  s  . c om
 * @param X
 * @param leaf_size
 * @param dist
 * @param logger
 */
protected NearestNeighborHeapSearch(final double[][] X, int leaf_size, DistanceMetric dist, Loggable logger) {
    this.data_arr = MatUtils.copy(X);
    this.leaf_size = leaf_size;
    this.logger = logger;

    if (leaf_size < 1)
        throw new IllegalArgumentException("illegal leaf size: " + leaf_size);

    if (!checkValidDistMet(dist)) {
        if (null != logger)
            logger.warn(dist + " is not valid for " + this.getClass() + ". Reverting to " + DEF_DIST);
        this.dist_metric = DEF_DIST;
    } else {
        this.dist_metric = dist;
    }

    // Whether the algorithm is using the infinity distance (Chebyshev)
    this.infinity_dist = this.dist_metric.getP() == Double.POSITIVE_INFINITY
            || Double.isInfinite(this.dist_metric.getP());

    // determine number of levels in the tree, and from this
    // the number of nodes in the tree.  This results in leaf nodes
    // with numbers of points between leaf_size and 2 * leaf_size
    MatUtils.checkDims(this.data_arr);
    N_SAMPLES = data_arr.length;
    N_FEATURES = X[0].length;

    /*
    // Should round up or always take floor function?...
    double nlev = FastMath.log(2, FastMath.max(1, (N_SAMPLES-1)/leaf_size)) + 1;
    this.n_levels = (int)FastMath.round(nlev);
    this.n_nodes = (int)(FastMath.pow(2, nlev) - 1);
    */

    this.n_levels = (int) (FastMath.log(2, FastMath.max(1, (N_SAMPLES - 1) / leaf_size)) + 1);
    this.n_nodes = (int) (FastMath.pow(2, n_levels) - 1);

    // allocate arrays for storage
    this.idx_array = VecUtils.arange(N_SAMPLES);

    // Add new NodeData objs to node_data arr
    this.node_data = new NodeData[n_nodes];
    for (int i = 0; i < node_data.length; i++)
        node_data[i] = new NodeData();

    // allocate tree specific data
    allocateData(this, n_nodes, N_FEATURES);
    recursiveBuild(0, 0, N_SAMPLES);
}

From source file:org.renjin.primitives.Ops.java

@Builtin("*")
@DataParallel(PreserveAttributeStyle.ALL)
public static Complex multiply(Complex x, Complex y) {
    // LICENSE: transcribed code from GCC, which is licensed under GPL
    // libgcc2 - Adapted by Tomas Kalibera
    // The Apache Commons math version does not handle edge cases
    // exactly the same as R/GCC does.

    double a = x.getReal();
    double b = x.getImaginary();
    double c = y.getReal();
    double d = y.getImaginary();

    double ac = a * c;
    double bd = b * d;
    double bc = b * c;
    double ad = a * d;

    double real = ac - bd;
    double imag = bc + ad;

    if (Double.isNaN(real) && Double.isNaN(imag)) {
        boolean recalc = false;
        double ra = a;
        double rb = b;
        double rc = c;
        double rd = d;
        if (Double.isInfinite(ra) || Double.isInfinite(rb)) {
            ra = convertInf(ra);//from  ww w.j  ava  2s.  co m
            rb = convertInf(rb);
            rc = convertNaN(rc);
            rd = convertNaN(rd);
            recalc = true;
        }
        if (Double.isInfinite(rc) || Double.isInfinite(rd)) {
            rc = convertInf(rc);
            rd = convertInf(rd);
            ra = convertNaN(ra);
            rb = convertNaN(rb);
            recalc = true;
        }
        if (!recalc && (Double.isInfinite(ac) || Double.isInfinite(bd) || Double.isInfinite(ad)
                || Double.isInfinite(bc))) {
            ra = convertNaN(ra);
            rb = convertNaN(rb);
            rc = convertNaN(rc);
            rd = convertNaN(rd);
            recalc = true;
        }
        if (recalc) {
            real = Double.POSITIVE_INFINITY * (ra * rc - rb * rd);
            imag = Double.POSITIVE_INFINITY * (ra * rd + rb * rc);
        }
    }
    return new Complex(real, imag);
}