Dlapy2.java
package org.mklab.sdpj.gpack.lapackwrap;
import org.mklab.nfc.matrix.ComplexNumericalMatrix;
import org.mklab.nfc.matrix.RealNumericalMatrix;
import org.mklab.nfc.scalar.ComplexNumericalScalar;
import org.mklab.nfc.scalar.RealNumericalScalar;
/**
* @author koga
* @version $Revision$, 2009/04/25
* @param <RS> type of real scalar
* @param <RM> type of real matrix
* @param <CS> type of complex scalar
* @param <CM> type of complex Matrix
*/
public class Dlapy2<RS extends RealNumericalScalar<RS, RM, CS, CM>, RM extends RealNumericalMatrix<RS, RM, CS, CM>, CS extends ComplexNumericalScalar<RS, RM, CS, CM>, CM extends ComplexNumericalMatrix<RS, RM, CS, CM>> {
/* -- LAPACK auxiliary routine (version 3.0) --
Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
Courant Institute, Argonne National Lab, and Rice University
October 31, 1992
Purpose
=======
DLAPY2 returns sqrt(x**2+y**2), taking care not to cause unnecessary
overflow.
Arguments
=========
X (input) DOUBLE PRECISION
Y (input) DOUBLE PRECISION
X and Y specify the values x and y.
===================================================================== */
/**
* @param x x
* @param y y
* @return result
*/
RS execute(RS x, RS y) {
RS xabs = x.abs();
RS yabs = y.abs();
RS w = xabs.max(yabs);
RS z = xabs.min(yabs);
RS ret_val;
if (z.isZero()) {
ret_val = w;
} else {
/* Computing 2nd power */
RS d1 = z.divide(w);
ret_val = w.multiply((d1.multiply(d1)).add(1).sqrt());
}
return ret_val;
}
}