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.

rotg.c 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #include <math.h>
  2. #include "common.h"
  3. #ifdef FUNCTION_PROFILE
  4. #include "functable.h"
  5. #endif
  6. #ifndef CBLAS
  7. void NAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
  8. #else
  9. void CNAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
  10. #endif
  11. #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_X64) || defined(_M_IX86)
  12. long double da = *DA;
  13. long double db = *DB;
  14. long double c;
  15. long double s;
  16. long double r, roe, z;
  17. long double ada = fabsl(da);
  18. long double adb = fabsl(db);
  19. long double scale = ada + adb;
  20. #ifndef CBLAS
  21. PRINT_DEBUG_NAME;
  22. #else
  23. PRINT_DEBUG_CNAME;
  24. #endif
  25. roe = db;
  26. if (ada > adb) roe = da;
  27. if (scale == ZERO) {
  28. *C = ONE;
  29. *S = ZERO;
  30. *DA = ZERO;
  31. *DB = ZERO;
  32. } else {
  33. r = sqrt(da * da + db * db);
  34. if (roe < 0) r = -r;
  35. c = da / r;
  36. s = db / r;
  37. z = ONE;
  38. if (da != ZERO) {
  39. if (ada > adb){
  40. z = s;
  41. } else {
  42. z = ONE / c;
  43. }
  44. }
  45. *C = c;
  46. *S = s;
  47. *DA = r;
  48. *DB = z;
  49. }
  50. #else
  51. FLOAT da = *DA;
  52. FLOAT db = *DB;
  53. FLOAT c = *C;
  54. FLOAT s = *S;
  55. FLOAT r, roe, z;
  56. FLOAT ada = fabs(da);
  57. FLOAT adb = fabs(db);
  58. FLOAT scale = ada + adb;
  59. #ifndef CBLAS
  60. PRINT_DEBUG_NAME;
  61. #else
  62. PRINT_DEBUG_CNAME;
  63. #endif
  64. roe = db;
  65. if (ada > adb) roe = da;
  66. if (scale == ZERO) {
  67. *C = ONE;
  68. *S = ZERO;
  69. *DA = ZERO;
  70. *DB = ZERO;
  71. } else {
  72. FLOAT aa = da / scale;
  73. FLOAT bb = db / scale;
  74. r = scale * sqrt(aa * aa + bb * bb);
  75. if (roe < 0) r = -r;
  76. c = da / r;
  77. s = db / r;
  78. z = ONE;
  79. if (ada > adb) z = s;
  80. if ((ada <= adb) && (c != ZERO)) z = ONE / c;
  81. *C = c;
  82. *S = s;
  83. *DA = r;
  84. *DB = z;
  85. }
  86. #endif
  87. return;
  88. }