dlas2.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* dlas2.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Subroutine */ int _starpu_dlas2_(doublereal *f, doublereal *g, doublereal *h__,
  14. doublereal *ssmin, doublereal *ssmax)
  15. {
  16. /* System generated locals */
  17. doublereal d__1, d__2;
  18. /* Builtin functions */
  19. double sqrt(doublereal);
  20. /* Local variables */
  21. doublereal c__, fa, ga, ha, as, at, au, fhmn, fhmx;
  22. /* -- LAPACK auxiliary routine (version 3.2) -- */
  23. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  24. /* November 2006 */
  25. /* .. Scalar Arguments .. */
  26. /* .. */
  27. /* Purpose */
  28. /* ======= */
  29. /* DLAS2 computes the singular values of the 2-by-2 matrix */
  30. /* [ F G ] */
  31. /* [ 0 H ]. */
  32. /* On return, SSMIN is the smaller singular value and SSMAX is the */
  33. /* larger singular value. */
  34. /* Arguments */
  35. /* ========= */
  36. /* F (input) DOUBLE PRECISION */
  37. /* The (1,1) element of the 2-by-2 matrix. */
  38. /* G (input) DOUBLE PRECISION */
  39. /* The (1,2) element of the 2-by-2 matrix. */
  40. /* H (input) DOUBLE PRECISION */
  41. /* The (2,2) element of the 2-by-2 matrix. */
  42. /* SSMIN (output) DOUBLE PRECISION */
  43. /* The smaller singular value. */
  44. /* SSMAX (output) DOUBLE PRECISION */
  45. /* The larger singular value. */
  46. /* Further Details */
  47. /* =============== */
  48. /* Barring over/underflow, all output quantities are correct to within */
  49. /* a few units in the last place (ulps), even in the absence of a guard */
  50. /* digit in addition/subtraction. */
  51. /* In IEEE arithmetic, the code works correctly if one matrix element is */
  52. /* infinite. */
  53. /* Overflow will not occur unless the largest singular value itself */
  54. /* overflows, or is within a few ulps of overflow. (On machines with */
  55. /* partial overflow, like the Cray, overflow may occur if the largest */
  56. /* singular value is within a factor of 2 of overflow.) */
  57. /* Underflow is harmless if underflow is gradual. Otherwise, results */
  58. /* may correspond to a matrix modified by perturbations of size near */
  59. /* the underflow threshold. */
  60. /* ==================================================================== */
  61. /* .. Parameters .. */
  62. /* .. */
  63. /* .. Local Scalars .. */
  64. /* .. */
  65. /* .. Intrinsic Functions .. */
  66. /* .. */
  67. /* .. Executable Statements .. */
  68. fa = abs(*f);
  69. ga = abs(*g);
  70. ha = abs(*h__);
  71. fhmn = min(fa,ha);
  72. fhmx = max(fa,ha);
  73. if (fhmn == 0.) {
  74. *ssmin = 0.;
  75. if (fhmx == 0.) {
  76. *ssmax = ga;
  77. } else {
  78. /* Computing 2nd power */
  79. d__1 = min(fhmx,ga) / max(fhmx,ga);
  80. *ssmax = max(fhmx,ga) * sqrt(d__1 * d__1 + 1.);
  81. }
  82. } else {
  83. if (ga < fhmx) {
  84. as = fhmn / fhmx + 1.;
  85. at = (fhmx - fhmn) / fhmx;
  86. /* Computing 2nd power */
  87. d__1 = ga / fhmx;
  88. au = d__1 * d__1;
  89. c__ = 2. / (sqrt(as * as + au) + sqrt(at * at + au));
  90. *ssmin = fhmn * c__;
  91. *ssmax = fhmx / c__;
  92. } else {
  93. au = fhmx / ga;
  94. if (au == 0.) {
  95. /* Avoid possible harmful underflow if exponent range */
  96. /* asymmetric (true SSMIN may not underflow even if */
  97. /* AU underflows) */
  98. *ssmin = fhmn * fhmx / ga;
  99. *ssmax = ga;
  100. } else {
  101. as = fhmn / fhmx + 1.;
  102. at = (fhmx - fhmn) / fhmx;
  103. /* Computing 2nd power */
  104. d__1 = as * au;
  105. /* Computing 2nd power */
  106. d__2 = at * au;
  107. c__ = 1. / (sqrt(d__1 * d__1 + 1.) + sqrt(d__2 * d__2 + 1.));
  108. *ssmin = fhmn * c__ * au;
  109. *ssmin += *ssmin;
  110. *ssmax = ga / (c__ + c__);
  111. }
  112. }
  113. }
  114. return 0;
  115. /* End of DLAS2 */
  116. } /* _starpu_dlas2_ */