gsl_cblas__source_rotmg.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /* blas/source_rotmg.h
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. {
  20. const BASE G = 4096.0, G2 = G * G;
  21. BASE D1 = *d1, D2 = *d2, x = *b1, y = b2;
  22. BASE h11, h12, h21, h22, u;
  23. BASE c, s;
  24. /* case of d1 < 0, appendix A, second to last paragraph */
  25. if (D1 < 0.0) {
  26. P[0] = -1;
  27. P[1] = 0;
  28. P[2] = 0;
  29. P[3] = 0;
  30. P[4] = 0;
  31. *d1 = 0;
  32. *d2 = 0;
  33. *b1 = 0;
  34. return;
  35. }
  36. if (D2 * y == 0.0) {
  37. P[0] = -2; /* case of H = I, page 315 */
  38. return;
  39. }
  40. c = fabs(D1 * x * x);
  41. s = fabs(D2 * y * y);
  42. if (c > s) {
  43. /* case of equation A6 */
  44. P[0] = 0.0;
  45. h11 = 1;
  46. h12 = (D2 * y) / (D1 * x);
  47. h21 = -y / x;
  48. h22 = 1;
  49. u = 1 - h21 * h12;
  50. if (u <= 0.0) { /* the case u <= 0 is rejected */
  51. P[0] = -1;
  52. P[1] = 0;
  53. P[2] = 0;
  54. P[3] = 0;
  55. P[4] = 0;
  56. *d1 = 0;
  57. *d2 = 0;
  58. *b1 = 0;
  59. return;
  60. }
  61. D1 /= u;
  62. D2 /= u;
  63. x *= u;
  64. } else {
  65. /* case of equation A7 */
  66. if (D2 * y * y < 0.0) {
  67. P[0] = -1;
  68. P[1] = 0;
  69. P[2] = 0;
  70. P[3] = 0;
  71. P[4] = 0;
  72. *d1 = 0;
  73. *d2 = 0;
  74. *b1 = 0;
  75. return;
  76. }
  77. P[0] = 1;
  78. h11 = (D1 * x) / (D2 * y);
  79. h12 = 1;
  80. h21 = -1;
  81. h22 = x / y;
  82. u = 1 + h11 * h22;
  83. D1 /= u;
  84. D2 /= u;
  85. {
  86. BASE tmp = D2;
  87. D2 = D1;
  88. D1 = tmp;
  89. }
  90. x = y * u;
  91. }
  92. /* rescale D1 to range [1/G2,G2] */
  93. while (D1 <= 1.0 / G2 && D1 != 0.0) {
  94. P[0] = -1;
  95. D1 *= G2;
  96. x /= G;
  97. h11 /= G;
  98. h12 /= G;
  99. }
  100. while (D1 >= G2) {
  101. P[0] = -1;
  102. D1 /= G2;
  103. x *= G;
  104. h11 *= G;
  105. h12 *= G;
  106. }
  107. /* rescale D2 to range [1/G2,G2] */
  108. while (fabs(D2) <= 1.0 / G2 && D2 != 0.0) {
  109. P[0] = -1;
  110. D2 *= G2;
  111. h21 /= G;
  112. h22 /= G;
  113. }
  114. while (fabs(D2) >= G2) {
  115. P[0] = -1;
  116. D2 /= G2;
  117. h21 *= G;
  118. h22 *= G;
  119. }
  120. *d1 = D1;
  121. *d2 = D2;
  122. *b1 = x;
  123. if (P[0] == -1.0) {
  124. P[1] = h11;
  125. P[2] = h21;
  126. P[3] = h12;
  127. P[4] = h22;
  128. } else if (P[0] == 0.0) {
  129. P[2] = h21;
  130. P[3] = h12;
  131. } else if (P[0] == 1.0) {
  132. P[1] = h11;
  133. P[4] = h22;
  134. }
  135. }