Blame thirdparty/openblas/xianyi-OpenBLAS-e6e87a2/interface/zrotg.c
|
kusano |
2b45e8 |
#include <math.h></math.h>
|
|
kusano |
2b45e8 |
#include "common.h"
|
|
kusano |
2b45e8 |
#ifdef FUNCTION_PROFILE
|
|
kusano |
2b45e8 |
#include "functable.h"
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
void NAME(FLOAT *DA, FLOAT *DB, FLOAT *C, FLOAT *S){
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
PRINT_DEBUG_NAME;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
IDEBUG_START;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FUNCTION_PROFILE_START();
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
#if defined(__i386__) || defined(__x86_64__) || defined(__ia64__)
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
long double da_r = *(DA + 0);
|
|
kusano |
2b45e8 |
long double da_i = *(DA + 1);
|
|
kusano |
2b45e8 |
long double db_r = *(DB + 0);
|
|
kusano |
2b45e8 |
long double db_i = *(DB + 1);
|
|
kusano |
2b45e8 |
long double r;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
long double ada = fabs(da_r) + fabs(da_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (ada == ZERO) {
|
|
kusano |
2b45e8 |
*C = ZERO;
|
|
kusano |
2b45e8 |
*(S + 0) = ONE;
|
|
kusano |
2b45e8 |
*(S + 1) = ZERO;
|
|
kusano |
2b45e8 |
*(DA + 0) = db_r;
|
|
kusano |
2b45e8 |
*(DA + 1) = db_i;
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
long double alpha_r, alpha_i;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
ada = sqrt(da_r * da_r + da_i * da_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
r = sqrt(da_r * da_r + da_i * da_i + db_r * db_r + db_i * db_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
alpha_r = da_r / ada;
|
|
kusano |
2b45e8 |
alpha_i = da_i / ada;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
*(C + 0) = ada / r;
|
|
kusano |
2b45e8 |
*(S + 0) = (alpha_r * db_r + alpha_i *db_i) / r;
|
|
kusano |
2b45e8 |
*(S + 1) = (alpha_i * db_r - alpha_r *db_i) / r;
|
|
kusano |
2b45e8 |
*(DA + 0) = alpha_r * r;
|
|
kusano |
2b45e8 |
*(DA + 1) = alpha_i * r;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#else
|
|
kusano |
2b45e8 |
FLOAT da_r = *(DA + 0);
|
|
kusano |
2b45e8 |
FLOAT da_i = *(DA + 1);
|
|
kusano |
2b45e8 |
FLOAT db_r = *(DB + 0);
|
|
kusano |
2b45e8 |
FLOAT db_i = *(DB + 1);
|
|
kusano |
2b45e8 |
FLOAT r;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FLOAT ada = fabs(da_r) + fabs(da_i);
|
|
kusano |
2b45e8 |
FLOAT adb;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (ada == ZERO) {
|
|
kusano |
2b45e8 |
*C = ZERO;
|
|
kusano |
2b45e8 |
*(S + 0) = ONE;
|
|
kusano |
2b45e8 |
*(S + 1) = ZERO;
|
|
kusano |
2b45e8 |
*(DA + 0) = db_r;
|
|
kusano |
2b45e8 |
*(DA + 1) = db_i;
|
|
kusano |
2b45e8 |
} else {
|
|
kusano |
2b45e8 |
FLOAT scale;
|
|
kusano |
2b45e8 |
FLOAT aa_r, aa_i, bb_r, bb_i;
|
|
kusano |
2b45e8 |
FLOAT alpha_r, alpha_i;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa_r = fabs(da_r);
|
|
kusano |
2b45e8 |
aa_i = fabs(da_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (aa_i > aa_r) {
|
|
kusano |
2b45e8 |
aa_r = fabs(da_i);
|
|
kusano |
2b45e8 |
aa_i = fabs(da_r);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
scale = (aa_i / aa_r);
|
|
kusano |
2b45e8 |
ada = aa_r * sqrt(ONE + scale * scale);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
bb_r = fabs(db_r);
|
|
kusano |
2b45e8 |
bb_i = fabs(db_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
if (bb_i > bb_r) {
|
|
kusano |
2b45e8 |
bb_r = fabs(bb_i);
|
|
kusano |
2b45e8 |
bb_i = fabs(bb_r);
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
scale = (bb_i / bb_r);
|
|
kusano |
2b45e8 |
adb = bb_r * sqrt(ONE + scale * scale);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
scale = ada + adb;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
aa_r = da_r / scale;
|
|
kusano |
2b45e8 |
aa_i = da_i / scale;
|
|
kusano |
2b45e8 |
bb_r = db_r / scale;
|
|
kusano |
2b45e8 |
bb_i = db_i / scale;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
r = scale * sqrt(aa_r * aa_r + aa_i * aa_i + bb_r * bb_r + bb_i * bb_i);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
alpha_r = da_r / ada;
|
|
kusano |
2b45e8 |
alpha_i = da_i / ada;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
*(C + 0) = ada / r;
|
|
kusano |
2b45e8 |
*(S + 0) = (alpha_r * db_r + alpha_i *db_i) / r;
|
|
kusano |
2b45e8 |
*(S + 1) = (alpha_i * db_r - alpha_r *db_i) / r;
|
|
kusano |
2b45e8 |
*(DA + 0) = alpha_r * r;
|
|
kusano |
2b45e8 |
*(DA + 1) = alpha_i * r;
|
|
kusano |
2b45e8 |
}
|
|
kusano |
2b45e8 |
#endif
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
FUNCTION_PROFILE_END(4, 4, 4);
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
IDEBUG_END;
|
|
kusano |
2b45e8 |
|
|
kusano |
2b45e8 |
return;
|
|
kusano |
2b45e8 |
}
|