You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

rotmg.c 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /***************************************************************************
  2. Copyright (c) 2013, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. /**************************************************************************************
  28. * 2014/05/02 Saar
  29. * fixed two bugs as reported by Brendan Tracey
  30. * Test with lapack-3.5.0 : OK
  31. *
  32. **************************************************************************************/
  33. #include "common.h"
  34. #ifdef FUNCTION_PROFILE
  35. #include "functable.h"
  36. #endif
  37. #define GAM 4096.e0
  38. #define GAMSQ 16777216.e0
  39. #define RGAMSQ 5.9604645e-8
  40. #define TWO 2.e0
  41. #ifdef DOUBLE
  42. #define ABS(x) fabs(x)
  43. #else
  44. #define ABS(x) fabsf(x)
  45. #endif
  46. #ifndef CBLAS
  47. void NAME(FLOAT *dd1, FLOAT *dd2, FLOAT *dx1, FLOAT *DY1, FLOAT *dparam){
  48. FLOAT dy1 = *DY1;
  49. #else
  50. void CNAME(FLOAT *dd1, FLOAT *dd2, FLOAT *dx1, FLOAT dy1, FLOAT *dparam){
  51. #endif
  52. FLOAT du, dp1, dp2, dq2, dq1, dh11=ZERO, dh21=ZERO, dh12=ZERO, dh22=ZERO, dflag=-ONE, dtemp;
  53. if (*dd2 == ZERO || dy1 == ZERO)
  54. {
  55. dflag = -TWO;
  56. dparam[0] = dflag;
  57. return;
  58. }
  59. if(*dd1 < ZERO)
  60. {
  61. dflag = -ONE;
  62. dh11 = ZERO;
  63. dh12 = ZERO;
  64. dh21 = ZERO;
  65. dh22 = ZERO;
  66. *dd1 = ZERO;
  67. *dd2 = ZERO;
  68. *dx1 = ZERO;
  69. }
  70. else if ((*dd1 == ZERO || *dx1 == ZERO) && *dd2 > ZERO)
  71. {
  72. dflag = ONE;
  73. dh12 = 1;
  74. dh21 = -1;
  75. *dx1 = dy1;
  76. dtemp = *dd1;
  77. *dd1 = *dd2;
  78. *dd2 = dtemp;
  79. }
  80. else
  81. {
  82. dp2 = *dd2 * dy1;
  83. if(dp2 == ZERO)
  84. {
  85. dflag = -TWO;
  86. dparam[0] = dflag;
  87. return;
  88. }
  89. dp1 = *dd1 * *dx1;
  90. dq2 = dp2 * dy1;
  91. dq1 = dp1 * *dx1;
  92. if(ABS(dq1) > ABS(dq2))
  93. {
  94. dh11 = ONE;
  95. dh22 = ONE;
  96. dh21 = - dy1 / *dx1;
  97. dh12 = dp2 / dp1;
  98. du = ONE - dh12 * dh21;
  99. if(du > ZERO)
  100. {
  101. dflag = ZERO;
  102. *dd1 = *dd1 / du;
  103. *dd2 = *dd2 / du;
  104. *dx1 = *dx1 * du;
  105. } else {
  106. dflag = -ONE;
  107. dh11 = ZERO;
  108. dh12 = ZERO;
  109. dh21 = ZERO;
  110. dh22 = ZERO;
  111. *dd1 = ZERO;
  112. *dd2 = ZERO;
  113. *dx1 = ZERO;
  114. }
  115. }
  116. else
  117. {
  118. if(dq2 < ZERO)
  119. {
  120. dflag = -ONE;
  121. dh11 = ZERO;
  122. dh12 = ZERO;
  123. dh21 = ZERO;
  124. dh22 = ZERO;
  125. *dd1 = ZERO;
  126. *dd2 = ZERO;
  127. *dx1 = ZERO;
  128. }
  129. else
  130. {
  131. dflag = ONE;
  132. dh21 = -ONE;
  133. dh12 = ONE;
  134. dh11 = dp1 / dp2;
  135. dh22 = *dx1 / dy1;
  136. du = ONE + dh11 * dh22;
  137. dtemp = *dd2 / du;
  138. *dd2 = *dd1 / du;
  139. *dd1 = dtemp;
  140. *dx1 = dy1 * du;
  141. }
  142. }
  143. while ( *dd1 <= RGAMSQ && *dd1 != ZERO)
  144. {
  145. dflag = -ONE;
  146. *dd1 = *dd1 * (GAM * GAM);
  147. *dx1 = *dx1 / GAM;
  148. dh11 = dh11 / GAM;
  149. dh12 = dh12 / GAM;
  150. }
  151. while (ABS(*dd1) > GAMSQ) {
  152. dflag = -ONE;
  153. *dd1 = *dd1 / (GAM * GAM);
  154. *dx1 = *dx1 * GAM;
  155. dh11 = dh11 * GAM;
  156. dh12 = dh12 * GAM;
  157. }
  158. while (ABS(*dd2) <= RGAMSQ && *dd2 != ZERO) {
  159. dflag = -ONE;
  160. *dd2 = *dd2 * (GAM * GAM);
  161. dh21 = dh21 / GAM;
  162. dh22 = dh22 / GAM;
  163. }
  164. while (ABS(*dd2) > GAMSQ) {
  165. dflag = -ONE;
  166. *dd2 = *dd2 / (GAM * GAM);
  167. dh21 = dh21 * GAM;
  168. dh22 = dh22 * GAM;
  169. }
  170. }
  171. if(dflag < ZERO)
  172. {
  173. dparam[1] = dh11;
  174. dparam[2] = dh21;
  175. dparam[3] = dh12;
  176. dparam[4] = dh22;
  177. }
  178. else
  179. {
  180. if(dflag == ZERO)
  181. {
  182. dparam[2] = dh21;
  183. dparam[3] = dh12;
  184. }
  185. else
  186. {
  187. dparam[1] = dh11;
  188. dparam[4] = dh22;
  189. }
  190. }
  191. dparam[0] = dflag;
  192. return;
  193. }