dlartg.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* dlartg.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_dlartg_(doublereal *f, doublereal *g, doublereal *cs,
  14. doublereal *sn, doublereal *r__)
  15. {
  16. /* System generated locals */
  17. integer i__1;
  18. doublereal d__1, d__2;
  19. /* Builtin functions */
  20. double log(doublereal), pow_di(doublereal *, integer *), sqrt(doublereal);
  21. /* Local variables */
  22. integer i__;
  23. doublereal f1, g1, eps, scale;
  24. integer count;
  25. doublereal safmn2, safmx2;
  26. extern doublereal _starpu_dlamch_(char *);
  27. doublereal safmin;
  28. /* -- LAPACK auxiliary routine (version 3.2) -- */
  29. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  30. /* November 2006 */
  31. /* .. Scalar Arguments .. */
  32. /* .. */
  33. /* Purpose */
  34. /* ======= */
  35. /* DLARTG generate a plane rotation so that */
  36. /* [ CS SN ] . [ F ] = [ R ] where CS**2 + SN**2 = 1. */
  37. /* [ -SN CS ] [ G ] [ 0 ] */
  38. /* This is a slower, more accurate version of the BLAS1 routine DROTG, */
  39. /* with the following other differences: */
  40. /* F and G are unchanged on return. */
  41. /* If G=0, then CS=1 and SN=0. */
  42. /* If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any */
  43. /* floating point operations (saves work in DBDSQR when */
  44. /* there are zeros on the diagonal). */
  45. /* If F exceeds G in magnitude, CS will be positive. */
  46. /* Arguments */
  47. /* ========= */
  48. /* F (input) DOUBLE PRECISION */
  49. /* The first component of vector to be rotated. */
  50. /* G (input) DOUBLE PRECISION */
  51. /* The second component of vector to be rotated. */
  52. /* CS (output) DOUBLE PRECISION */
  53. /* The cosine of the rotation. */
  54. /* SN (output) DOUBLE PRECISION */
  55. /* The sine of the rotation. */
  56. /* R (output) DOUBLE PRECISION */
  57. /* The nonzero component of the rotated vector. */
  58. /* This version has a few statements commented out for thread safety */
  59. /* (machine parameters are computed on each entry). 10 feb 03, SJH. */
  60. /* ===================================================================== */
  61. /* .. Parameters .. */
  62. /* .. */
  63. /* .. Local Scalars .. */
  64. /* LOGICAL FIRST */
  65. /* .. */
  66. /* .. External Functions .. */
  67. /* .. */
  68. /* .. Intrinsic Functions .. */
  69. /* .. */
  70. /* .. Save statement .. */
  71. /* SAVE FIRST, SAFMX2, SAFMIN, SAFMN2 */
  72. /* .. */
  73. /* .. Data statements .. */
  74. /* DATA FIRST / .TRUE. / */
  75. /* .. */
  76. /* .. Executable Statements .. */
  77. /* IF( FIRST ) THEN */
  78. safmin = _starpu_dlamch_("S");
  79. eps = _starpu_dlamch_("E");
  80. d__1 = _starpu_dlamch_("B");
  81. i__1 = (integer) (log(safmin / eps) / log(_starpu_dlamch_("B")) / 2.);
  82. safmn2 = pow_di(&d__1, &i__1);
  83. safmx2 = 1. / safmn2;
  84. /* FIRST = .FALSE. */
  85. /* END IF */
  86. if (*g == 0.) {
  87. *cs = 1.;
  88. *sn = 0.;
  89. *r__ = *f;
  90. } else if (*f == 0.) {
  91. *cs = 0.;
  92. *sn = 1.;
  93. *r__ = *g;
  94. } else {
  95. f1 = *f;
  96. g1 = *g;
  97. /* Computing MAX */
  98. d__1 = abs(f1), d__2 = abs(g1);
  99. scale = max(d__1,d__2);
  100. if (scale >= safmx2) {
  101. count = 0;
  102. L10:
  103. ++count;
  104. f1 *= safmn2;
  105. g1 *= safmn2;
  106. /* Computing MAX */
  107. d__1 = abs(f1), d__2 = abs(g1);
  108. scale = max(d__1,d__2);
  109. if (scale >= safmx2) {
  110. goto L10;
  111. }
  112. /* Computing 2nd power */
  113. d__1 = f1;
  114. /* Computing 2nd power */
  115. d__2 = g1;
  116. *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
  117. *cs = f1 / *r__;
  118. *sn = g1 / *r__;
  119. i__1 = count;
  120. for (i__ = 1; i__ <= i__1; ++i__) {
  121. *r__ *= safmx2;
  122. /* L20: */
  123. }
  124. } else if (scale <= safmn2) {
  125. count = 0;
  126. L30:
  127. ++count;
  128. f1 *= safmx2;
  129. g1 *= safmx2;
  130. /* Computing MAX */
  131. d__1 = abs(f1), d__2 = abs(g1);
  132. scale = max(d__1,d__2);
  133. if (scale <= safmn2) {
  134. goto L30;
  135. }
  136. /* Computing 2nd power */
  137. d__1 = f1;
  138. /* Computing 2nd power */
  139. d__2 = g1;
  140. *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
  141. *cs = f1 / *r__;
  142. *sn = g1 / *r__;
  143. i__1 = count;
  144. for (i__ = 1; i__ <= i__1; ++i__) {
  145. *r__ *= safmn2;
  146. /* L40: */
  147. }
  148. } else {
  149. /* Computing 2nd power */
  150. d__1 = f1;
  151. /* Computing 2nd power */
  152. d__2 = g1;
  153. *r__ = sqrt(d__1 * d__1 + d__2 * d__2);
  154. *cs = f1 / *r__;
  155. *sn = g1 / *r__;
  156. }
  157. if (abs(*f) > abs(*g) && *cs < 0.) {
  158. *cs = -(*cs);
  159. *sn = -(*sn);
  160. *r__ = -(*r__);
  161. }
  162. }
  163. return 0;
  164. /* End of DLARTG */
  165. } /* _starpu_dlartg_ */